Sign in to follow this  
qzole

How to create a bitmap from vector of color int GDI

Recommended Posts

Hi all! //problem after this phrase I want to use png images in my program, with gdi, and because of the lack of time, I wanted a fast solution for loading png images. Well, I looked at libpng and... I really only need to load png files, I don't want to make a new photshop :) So I luckly found Lode's greate png decoder/encoder, and downloaded from his site the great picoPNG, just what I need, doesn't do anything fancy just loads png images, easy to use, compiles without problems, as for understanding, as I said I don't have the time now to learn about pngs. //problem So the problem is I used picoPNG, I got the vector, but I don't really know how can I create a Bitmap from it for the GDI (not GDI+). Tried whit CreateBitmap HBITMAP CreateBitmap( int nWidth, // bitmap width, in pixels int nHeight, // bitmap height, in pixels UINT cPlanes, // number of color planes UINT cBitsPerPel, // number of bits to identify color CONST VOID *lpvBits // color data array ); But I don't really know the number of color planes, or what does it represent, and I don't know for sure, if it accepts the vector as the color data array, I tired, but it returned with a NULL handle, which means error. Could someone help, or point somewhere where it writes it down clearly? Thank you in advance, And thanks Lode for the great PNG decoder, Q.

Share this post


Link to post
Share on other sites
You should use CreateDIBitmap. It can be a bit complicated if this is your first time playing with this stuff but you should be able to google lots of code demonstrating how to use it.

The number of planes will be 1. Unless you are posting from the 80's and you're having issues with your EGA card. biSizeImage, *PelsPerMeter, biClrUsed, and biClrImportant can all be left as 0.

A common error is that CreateDIBitmap requires scanlines to be padded out to be a multiple of a DWORD. This can be an issue with color depths less than 32bpp.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this