Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Saving a DIB to BMP file

Status
Not open for further replies.

BigInch

Petroleum
Jun 21, 2006
15,161
0
0
GB
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?

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[worm]-born in the trenches.
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top