phro
February 9th, 2000, 01:37 AM
Okay, my question is this. I am using the api call LoadImage from the
user32 lib in VisualBasic 5. I've created a DC to load the image into
and getting it there seems to work allright. But when I bitblt it onto
a form my 24bit true color bitmap comes up in 8 bit ugliness. What am I
doing wrong?
'the code I'm using ....
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long,
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As
Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As
Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal
dwRop As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
hObject As Long) As Long
Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
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 Const IMAGE_BITMAP As Long = 0
Public Const LR_LOADFROMFILE As Long = 10
Public Const LR_CREATEDIBSECTION As Long = 2000
Public Const LR_LOADMAP3DCOLORS As Long = 1000
Public tileDC As Long
Public Function GenerateDC(FileName As String) As Long
Dim DC As Long
Dim hBitmap As Long
'Create a Device Context
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
MsgBox "'Handle to a DC' creation error!"
Exit Function
End If
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or
LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
MsgBox "Failure loading bitmap!"
Exit Function
End If
'Throw the Bitmap into the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
DeleteObject hBitmap
End Function
Sub Loadit(bitmapfile As String)
tileDC = GenerateDC(bitmapfile)
retval = BitBlt(frmMain.hdc, 0, 0, 128, 2048, tileDC, 0, 0, vbSrcCopy)
End Sub
user32 lib in VisualBasic 5. I've created a DC to load the image into
and getting it there seems to work allright. But when I bitblt it onto
a form my 24bit true color bitmap comes up in 8 bit ugliness. What am I
doing wrong?
'the code I'm using ....
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long,
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As
Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As
Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal
dwRop As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
hObject As Long) As Long
Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
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 Const IMAGE_BITMAP As Long = 0
Public Const LR_LOADFROMFILE As Long = 10
Public Const LR_CREATEDIBSECTION As Long = 2000
Public Const LR_LOADMAP3DCOLORS As Long = 1000
Public tileDC As Long
Public Function GenerateDC(FileName As String) As Long
Dim DC As Long
Dim hBitmap As Long
'Create a Device Context
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
MsgBox "'Handle to a DC' creation error!"
Exit Function
End If
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or
LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
MsgBox "Failure loading bitmap!"
Exit Function
End If
'Throw the Bitmap into the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
DeleteObject hBitmap
End Function
Sub Loadit(bitmapfile As String)
tileDC = GenerateDC(bitmapfile)
retval = BitBlt(frmMain.hdc, 0, 0, 128, 2048, tileDC, 0, 0, vbSrcCopy)
End Sub