I have been playing with an idea of how to embed image data into a PB executable that is not stored as a resource but as BYTE data, something that is easy enough to do as a DB block and while the code I have written produces the correct "GetLastError" values and the STATIC control I am trying to put it in resizes to the image size, not for love nor money can I get the image to display. This is the bare code without the byte data storage.
bmp.bmType = 0
bmp.bmWidth = 64
bmp.bmHeight = 64
bmp.bmWidthBytes = 64*3
bmp.bmPlanes = 1
bmp.bmBitsPixel = 24
bmp.bmBits = oldbook_bmp(0) ' +54
hBmp = CreateBitmapIndirect(ByVal VarPtr(bmp.bmType))
The "oldbook_bmp" is a valid pointer to the BYTE data, the structure (UDT) is a normal BITMAP structure that has been tweaked so the last member is a DWORD, not a BYTE PTR. The image is a 64 x 64 pixel 24 bit bitmap.
When I test the size of the STATIC control after the code is run it has been resized to 64 x 64 after calling,
SendMessage GetDlgItem(hDlg,999),%STM_SETIMAGE,%IMAGE_BITMAP,hBmp
If I load the bitmap as a resource and call it with LoadImage() everything works as expected.
Has anyone ever got CreateBitmapIndirect() to work on a 24 bit bitmap ?
Quote
While the CreateBitmapIndirect function can be used to create color bitmaps, for performance reasons applications should use CreateBitmapIndirect to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color bitmap from CreateBitmapIndirect is selected into a device context, the system must ensure that the bitmap matches the format of the device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns a bitmap that has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color bitmap from CreateCompatibleBitmap than with a color bitmap returned from CreateBitmapIndirect.
...
Patrice,
The speed issue did not worry me, it was that it did not display even though the return values from GetLastError kept saying it succeeded.
What I am looking for is a method where I can specify the byte data for a bitmap and end up with a working bitmap handle. LoadImage will load from a file but it will not load from a memory address.
LATER : Not to worry, I foud a clean and simple way around it.