Hello,

I am attempting to convert a Windows BMP byte stream/array into a PNG format. I am unable to modify how this byte stream comes in.

My attempts:
I've tried using lodepng (http://members.gamedev.net/lode/projects/LodePNG/), but it only supports RGBA format for bitmaps (mine is only BGR, I believe). I've also tried the Windows Imaging Component (http://msdn.microsoft.com/en-us/magazine/cc500647.aspx). However, it gets stuck at this piece of code:

CComPtr<IStream> sourceStream;
sourceStream->Write(bitmap.data.data, bitmap.data.size, NULL);

Here, bitmap.data.data is the BMP byte stream. I'm attempting to write this into the IStream for use with the WIC. However, an assertion fails. It believes that I'm passing it a null array, which I'm not (I have verified this).

I know that my other option is using libpng, but I'm completely confused as to how it works, even after reading the documentation.

Does anyone have any suggestions?

Thanks, I found all of those on google already :) My data stream is having problems with the WIC. It doesn't like it.

You don't need any code. (nearly..)
Conversion is native in Win32 (Shell or GDI apis)

commented: Another one of your 100% non-helpfull posts -4

GDI, not GDI+, correct? I'm unable to use GDI+ in this one. Do you have any information about this?

Ok, so I got it working using LodePNG:

LodePNG::Encoder encoder;
encoder.infoRaw.color.colorType = 2; //RGB
encoder.encode(buffer, out_image, WIDTH, HEIGHT); //out_image is the vector containing the RGB bitmap data, buffer is the output vector
LodePNG::saveFile(buffer, "C:\\files\\PNGTest_OUT.png"); // a test png file is saved to make sure that the conversion worked

However, LodePNG appears to be way too slow for my application. I can open, convert, and save an image every 3 seconds with the most optimal settings. However, I would like to be able to do at least 10 VGA-sized conversions per second. I hear that libpng's use of zlib makes it run much faster, but I have no idea how to use conversion with libpng. Does anyone have any suggestions or links to documentation besides what's available at the libpng website?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.