PNG Encoding

Started by
3 comments, last by Evil Bill 21 years ago
I've had a look at the search page, and didn't find anything useful... I'm trying to write a program to generate PNG images from a bitmap, but i can't get it working. It seems that zlib is compressing my 110 byte bitmap data down to 12 bytes, surely thats not right? My input image looks like this: My pretty picture And heres the code for the compression:
        
   // Setup compression stream //

   ZeroMemory(&theStream,sizeof(theStream));
   deflateInit(&theStream,9);
   theStream.next_in = pbyInput;
   theStream.avail_in = (bmpInfo.bmWidth+1)*bmpInfo.bmHeight;
   theStream.total_in = 0;
   theStream.next_out = pbyData;
   theStream.avail_out = dwLen;
   theStream.total_out = 0;
   
   // Compress Chunk //

   if(deflate(&theStream,Z_FINISH) != Z_STREAM_END) goto lblError;
   delete[] pbyInput;
   pbyInput = NULL;
   
   // Write Chunk//

   // Snipped - just writes theStream.total_out bytes to file //

   delete[] pbyData;
   pbyData = NULL;

   deflateEnd(&theStream);
    
I get my image data from GetObject() on a DIB section, and i copy it into pbyInput, adding a 0 byte at the start of each scanline (for the filter type), so in total my input data is 110 bytes. Any help would be great. [edited by - Evil Bill on April 19, 2003 10:41:03 AM] [edited by - Evil Bill on April 19, 2003 10:41:30 AM] [edited by - Evil Bill on April 19, 2003 11:45:51 AM]
Member of the Unban Mindwipe Society (UMWS)
Advertisement
quote:Original post by Evil Bill
It seems that zlib is compressing my 110 byte bitmap data down to 12 bytes, surely thats not right?


Since your image is very simple, such a result wouldn''t surprise me at all. If you really want to make sure it work, why don''t you uncompress it and see if you get the original image ?
quote:
If you really want to make sure it work, why don''t you uncompress it and see if you get the original image ?

D''oh! I''ll try that now...

Member of the Unban Mindwipe Society (UMWS)
Ok, i made a stupid mistake so it was saving 110 bytes of 0x00's, now it outputs 63 bytes, which is much more realistic.

But it still doesn't work . I tried inflating the data after i deflated it and it comes out the same as it went in, so its compressing it ok.
I'll rename the topic to something to do with PNGs i think.



[edited by - Evil Bill on April 19, 2003 11:45:31 AM]
Member of the Unban Mindwipe Society (UMWS)
quote:Original post by Evil Bill
But it still doesn''t work . I tried inflating the data after i deflated it and it comes out the same as it went in, so its compressing it ok.


What doesn''t work if it''s compressing it well ? By the way, if you want to create PNG images, you should perhaps use libPNG, it would be much easier.

This topic is closed to new replies.

Advertisement