Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

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.

0
ShadowHawk071998
Asked:
ShadowHawk071998
  • 2
  • 2
1 Solution
 
nietodCommented:
Just let the windows bitmap structures "be your guide"

First write out a BITMAPFILEHEADER structure at the start of the file.  You can set the 2 reserved members to 0.  The last member is the offfset to the pixel data.  You can calculate that, but you can also just leave it as 0 at the start and set it later.

continues
0
 
nietodCommented:
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.
0
 
ShadowHawk071998Author Commented:
Answer accepted
0
 
ShadowHawk071998Author Commented:
Hey. This worked, really. Thanks...

sorry for the late reply.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now