Link to home
Start Free TrialLog in
Avatar of ShadowHawk071998
ShadowHawk071998

asked on

How to write a bmp file from Pixel values and colour table

hello guys.
I have two buffers, one that contains Pixel values, and one that contains Colour Table Data.
I got those buffers from using LoadImage and then processing the HBITMAP that is the result...
These values are written to a file. Now I need to load the file, which contains those two buffers, and save it as a bitmap file (bmp). How do I do it? I'm getting all mixed up with DIBs and DDBs and stuff like that. I thought that what I have IS a bitmap!

Anyway. The colour table size is always 256*3 (Although some of the images are 24bit colour, and then there is NO colour table, and each pixel takes 3 bytes (RGB).

Thanks,

Ron.

ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

Following this you need to write a BITMAPINFOHEADER structure.  this tells the format of the pixel data.  I don't know what format you are using, so I can't help there.  You should be able to figure out how to fill it in from what you know.  If not, try to describe your format to me.

Following this you need to write an array of RGBQUAD values for the bitmap's color table.

After this you write the pixel data.  Now this is the offset that needs to be written in the BITMPAPFILEHEADER.  you can obtain the current size of the file and at this pointer--before writting the pixel data--and save it so that you can go back to write the offset at the end.   alternately you can calulate this position at the start.  As you can now see it should be

sizeof(BITMAPFILEHEADER) + sizof(BITMAPINFOHEADER) + ColorTableSize*sizeof(RGBQUAD);

That's about all there is to it.  give it a try and let me know if you have any problems or questions.
Avatar of ShadowHawk071998

ASKER

Answer accepted
Hey. This worked, really. Thanks...

sorry for the late reply.