
save bmp in same depth as loaded bmp
I am using the following code to load a 4bit (16 color) bitmap image. I am
not normally a graphics programmer but I think I understand the following
code. When I get the BITMAP structure, the BMP.bmBitsPixel seems to match my
screen solor resolution regardless of the image color resolution. All I want
to do is draw some text on top of the bitmap image in the device context,
which I can do OK, but I would like to output the image in the same
resolution that it was to begin with. Any ideas on how to do this? If the
input image is 4 bit, then I want to load it, draw some text on it, and save
it again as 4 bit (same with 8 bit...etc... not dependent on screen
resolution) This part kind of stumps me...any help or sample code is very
much appreciated.
' load the bmp, get handle
Dim hBmp As Long
hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE Or LR_DEFAULTSIZE)
Debug.Print "hBmp:", hBmp
' create dc
Dim hDC As Long
hDC = CreateCompatibleDC(0)
Debug.Print "hDC:", hDC
' select bmp into dc
Dim hBmp0
hBmp0 = SelectObject(hDC, hBmp)
' get some bitmap information
Dim BMP As BITMAP
GetObjectAPI hBmp, Len(BMP), BMP
Debug.Print BMP.bmWidth & "x" & BMP.bmHeight, BMP.bmBitsPixel,
BMP.bmWidthBytes
....draw some text in the hDC (code intentionally left out)
....save image in original format (this is the stumper)
SelectObject hDC, hBmp0
DeleteObject hDC
(please not this is done using only API's in a module, there will be no form
components to use; and speed and memory are important factors)