Solved

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

Posted on 2000-05-18
4
355 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
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

772 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