Saving a DIB to BMP file
Saving a DIB to BMP file
(OP)
I am using this code to try to write a DIB to a 24 bit BMP file on disk. It almost works. The only problem I'm having is the colors are wrong. It seems to be reversing RGB values. Would someone kindly offer a correction?
' Open the output bitmap file.
fnum = FreeFile
Open fn For Binary As fnum
' Write the BITMAPFILEHEADER.
Put #fnum, , bitmap_file_header
' Write the BITMAPINFOHEADER.
' (Note that memBmp.bitmap_info.bmiHeader.biHeight
' must be positive for this.)
Put #fnum, , membmp.bitmap_info
' Get the DIB bits.
ReDim pixels(1 To 4, 1 To membmp.wid, 1 To membmp.hgt)
GetDIBits membmp.hdc, membmp.hBM, _
0, membmp.hgt, pixels(1, 1, 1), _
membmp.bitmap_info, DIB_RGB_COLORS
' Write the DIB bits.
Put #fnum, , pixels
' Close the file.
Close fnum
Thanks!
CODE
' Open the output bitmap file.
fnum = FreeFile
Open fn For Binary As fnum
' Write the BITMAPFILEHEADER.
Put #fnum, , bitmap_file_header
' Write the BITMAPINFOHEADER.
' (Note that memBmp.bitmap_info.bmiHeader.biHeight
' must be positive for this.)
Put #fnum, , membmp.bitmap_info
' Get the DIB bits.
ReDim pixels(1 To 4, 1 To membmp.wid, 1 To membmp.hgt)
GetDIBits membmp.hdc, membmp.hBM, _
0, membmp.hgt, pixels(1, 1, 1), _
membmp.bitmap_info, DIB_RGB_COLORS
' Write the DIB bits.
Put #fnum, , pixels
' Close the file.
Close fnum
Thanks!
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Saving a DIB to BMP file
h
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com