Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Btibltting

Status
Not open for further replies.

markbellki

Technical User
Jan 21, 2003
7
AU
I have written a program that converts graphic images into bitmaps. My problem is that I'm trying to bitblt this image into a picture box that has a picture in it already. That is, I needed the converted-bitmap to be transparent. I managed to do it and it works fine on my Win98 computer. When I send it to others who have WinXP, the bitblt routine doesn't work. The bitmap will not appear in the picturebox.

Any ideas?
 
haven't had any trouble with bitblt on XP. maybe if you post the part of your code where you set up your DCs and handles and where you call bitblt we can check if there is something else that could be a potential problem on XP...
 
Thanks for any help that you can provide.

Declare Function TransparentBlt Lib "msimg32" (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

Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Public Type Bitmap '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Public Const LR_CREATEDIBSECTION = &H2000
Public Const LR_LOADFROMFILE = &H10

Sub GetDimensions()
Dim dbitmap As Bitmap
Dim hbitmap As Long
Dim filename As String

filename = Bitmap_Name
hbitmap = LoadImage(ByVal 0&, filename, 0, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)

' Get bitmap information
GetObject hbitmap, Len(dbitmap), dbitmap

hdcHeight = dbitmap.bmHeight
hdcWidth = dbitmap.bmWidth
DeleteObject hbitmap
End Sub

Private Sub Display()
Dim TransparentColor As Long
Dim cpX, cpY 'centerpoint coordinates


picSource.Picture = LoadPicture(Bitmap_Name)
picDest.Refresh
picSource.Refresh
hdcSrc = picSource.hdc
GetDimensions

picDest.Picture = Picture2.Picture

X = 417
Y = 271
cpX = 417
cpY = 271

Xc = InputBox("What is the cFootprintX number of the graphic? ", "UAPE v1.0", 1, 600, 600)
Yc = InputBox("What is the cFootprintY number of the graphic? ", "UAPE v1.0", 1, 600, 600)

cpX = 418 - (Xc - 1) * 8 + (Yc - 1) * 8
cpY = 265 - (Xc - 1) * 4 - (Yc - 1) * 4

If Direction_String = "NW" Or Direction_String = "SE" Then
X = X - Width_Animation + Width_Animation - CP_Width + cpX - X + ((Xc - Yc) * 15)
Y = Y - Height_Animation + Height_Animation - CP_Height + cpY - Y
Else
X = X - Width_Animation + Width_Animation - CP_Width + cpX - X
Y = Y - Height_Animation + Height_Animation - CP_Height + cpY - Y
End If

TransparentColor = GetPixel(hdcSrc, 0, 0)

TransparentBlt picDest.hdc, X, Y, hdcWidth, hdcHeight, hdcSrc, 0, 0, hdcWidth, hdcHeight, TransparentColor
picDest.Refresh

End Sub

Private Sub Form_Load()

ch = CP_Height
cw = CP_Width
Xc = 0
Yc = 0
yct = 0
xct = 0
YChange = 0
XChange = 0
Form6.Show
Display

End Sub
 
For some reason TransparentBlt does not work if the source picture(haven't checked if the same is true for the dest) has the AutoSize property set to True on XP. I can't even guess why. Maybe this is your problem. I don't see anything else that could be an issue. They do recommend a DoEvents before calling TransparentBlt. Let me know how you make out.
 
Thanks for your help.

The source picture didn't have the AutoSize property set to True but the dest did. Have changed it and sent it on to some testers (I don't have WinXP, have Win98).

Will let you know the result.
 
umm, I am working on a project that uses TransparentBlt and I noticed that the autosize property IS set to True on both pictures. I must have been mistaken before when I associated my problem with the Autosize property. Sorry to send you on a wild goose chase. I haven't had any other problems with TransparentBlt on XP. My only suggestion would be to set up a simple program that just does an arbritrary, simplified TransparentBlt around a Form, so as to rule out any chance that there is an offset or other error. Then if this works, you know the problem lies elsewhere and if it doesn't it certainly lies with TransparentBlt and I would think this would be a known issue by Microsoft, MSDN may have advice.


 
Thanks for your tips Cykadelyxx.

My testers returned a negative answer to the program working.

Am now convinced myself that there is something wrong with the code somewhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top