
Originally Posted by
BenJones
I always used to use TransparentBlt and it worked fine I used to use the pixel background color as 255,0,255, I tryed setting your original image to transpaent in a image editor and noticed there was still a little pink around the image. have you tryed a gif file. or what else you chould do it look at the first pixel and replace all that color with button face but I duno why TransparentBlt won't work. I wish I still has VB6 I know use C# so I can only guess I don't think my old VB6 will install anymore.
I did try something like this, but for some reason it wont change nothing:
Code:
Private Declare Function TransparentBlt Lib "msimg32.dll" ( _
ByVal hdcDest As Long, _
ByVal nXOriginDest As Long, _
ByVal nYOriginDest As Long, _
ByVal nWidthDest As Long, _
ByVal nHeightDest As Long, _
ByVal hdcSrc As Long, _
ByVal nXOriginSrc As Long, _
ByVal nYOriginSrc As Long, _
ByVal nWidthSrc As Long, _
ByVal nHeightSrc As Long, _
ByVal crTransparent As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Sub SetTransparentBackground(picBox As PictureBox, transparentColor As Long)
Dim hdcDest As Long
Dim hdcSrc As Long
Dim bmpWidth As Long
Dim bmpHeight As Long
' Get the device context (DC) of the destination PictureBox
hdcDest = picBox.hdc
' Create a memory DC for the source bitmap
hdcSrc = CreateCompatibleDC(hdcDest)
' Select the bitmap into the memory DC
Dim hOldBmp As Long
hOldBmp = SelectObject(hdcSrc, picBox.Picture.Handle)
' Get the dimensions of the bitmap
bmpWidth = picBox.ScaleWidth
bmpHeight = picBox.ScaleHeight
' Perform the transparent blit
TransparentBlt hdcDest, 0, 0, bmpWidth, bmpHeight, _
hdcSrc, 0, 0, bmpWidth, bmpHeight, transparentColor
' Clean up
SelectObject hdcSrc, hOldBmp
DeleteDC hdcSrc
End Sub
Also I tried to change the background color with "BitBlt", but again I got an empty Picturebox.
I just got from Windows 7 to 10 and it's working almost fine.