Solved

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

Posted on 2000-05-18
4
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 333 total points
ID: 2821649
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
ID: 2821687
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
ID: 2859333
Answer accepted
0
 

Author Comment

by:ShadowHawk071998
ID: 2859334
Hey. This worked, really. Thanks...

sorry for the late reply.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

734 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