Which is faster, GDI+ or libpng?
I have an HBITMAP
and I would like to convert it to png format(in memory I have malloc'd)as fast as possible, so my question is should I go with GDI+
or libpng
?
I've tried using GDI+
, but it doesn't seem as fast 开发者_开发百科as I would like it to be.
I've also tried FreeImage
and it was way too slow.
In my tests, running libpng with its default settings is roughly 2 to 3 times slower than GDI+, but tends to produce more highly compressed png files.
The results vary considerably depending on the input bitmap. On one extreme, I had a 1680x1050 bitmap which libpng took about 1.23 seconds to encode as a 1531k png; GDI+ took only 0.35 secs to process that bitmap, but its png was a whopping 2391k. But for another bitmap of the same size (actually a screen grab of this stack overflow page) libpng generated 294k png in 0.305 seconds while GDI+ generated a 318k png in 0.097 seconds.
According to pngcheck, the GDI+ generated pngs don't do any row-level predictive filtering and also use a fast version of zlib compression. Libpng uses "default zlib compression" and also appears to use different predictive filters depending on the contents of a row and its neighbours. Presumably you could use png_set_compression_level()
to get libpng to produce a size/speed trade-off similar to what GDI+ gives you.
One final point -- I used PNG_INTERLACE_NONE in my png tests. PNG_INTERLACE_ADAM7 seemed to really hurt png compression ratios, so I'd avoid it unless you really want progressive rendering of your images.
精彩评论