Solved

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

Posted on 2000-05-18
4
352 Views
Last Modified: 2010-04-02
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
Comment
Question by:ShadowHawk071998
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 333 total points
Comment Utility
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
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
 

Author Comment

by:ShadowHawk071998
Comment Utility
Answer accepted
0
 

Author Comment

by:ShadowHawk071998
Comment Utility
Hey. This worked, really. Thanks...

sorry for the late reply.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now