?
Solved

Saving a bitmap on file

Posted on 2001-09-10
7
Medium Priority
?
249 Views
Last Modified: 2013-12-03
Hi ALL !!!
   Last 2 days I'm struggling to save the bmp on the file.The main problem with my code is when I use DIBSECTION structure to get the values of the bmp structures the value obtained are correct but when I use BITMAPINFO structure the value are incorrect. I am refferencing DIBLLOKEX code which is on codeguru site for saving the bmp. Every other things are proper(size, height, width of the saved bmp) except that when i open this saved file it shows only a block rectangle of the same size that of the bmp which i saved.
  I guess this is because the bit values are not correctly stored. Can anybody tell me how to get the bit values from the DIBSECTION structure? I've tried "GetBitmapBits" API but still giving the same problem.
  The bitmap is 256 bits.

Thanks in advance
Nitin
0
Comment
Question by:nitinkale
[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
7 Comments
 
LVL 9

Expert Comment

by:Pacman
ID: 6470303
>> I guess this is because the bit values are not correctly stored.

You can check this by viewing the file with hex editor.
What is the color depth of the bitmap ?
0
 
LVL 5

Accepted Solution

by:
FengYuan earned 400 total points
ID: 6475754
1) From DIBSECTION.dsBmih you have BITMAPINFOHEADER
2) From GetDIBColorTable, you get RGBQUAD array
3) From DIBSECTION.dsBm.bmBits, you get pointer to the pixel array.

Add BITMAPFILEHEADER, you get a complete .BMP file

Feng Yuan www.fengyuan.com
0
 
LVL 1

Expert Comment

by:dspector
ID: 6484796
You can store simply and directly by converting your HBITMAP to a DIB in a memory block, then storing the memory block to a file. DIB format is the same whether in memory or in a file, since it is device independent.

Let me know if you need working code.

David
0
 
LVL 9

Expert Comment

by:Pacman
ID: 6486720
>> The bitmap is 256 bits

I guess you mean 256 colors.
I asked for the color depth because if you use 256 colors then you'll have to store a color palette in your bitmap file.
Maybe you wrote an "empty" palette to the file.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

752 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