Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Seeking PNG Compression algorithm/library [closed]

I need to compress or at least drop the quality of some png images that users are uploading to my site. I already resized it but that doesn't do much for the image size.

Seeking a png/image compression or quality loss algorithm or library for .net 4.0 or under.


This is how I currently save/convert my images:

Image mainImg = ImageHelper.ResizeImage(bmp, 600, 500, false);
mainImg.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
like image 467
Shawn Mclean Avatar asked Dec 11 '10 19:12

Shawn Mclean


1 Answers

Unfortunately, .NET (and GDI+, which the .NET graphics libraries are built on) does not support any encoding parameters for PNG. In fact, if you call GetEncoderParameterList on your image with the PNG encoder Clsid, you'll get a "Not implemented" exception.

Even more unfortunate is that both ImageFormat and ImageCodecInfo are sealed classes and you can't just add new codecs to what .NET can natively access. Microsoft dropped the ball on this one.

This means your alternatives are, in decreasing order of masochism: 1) Implement a save function on your own in .NET that implements RFC 2083, 2) Implement a save function based off porting libpng to .NET, 3) Call unmanaged code that was built from libpng directly

libpng has great documentation and is free, both in availability and license permissiveness.

like image 144
Applekid Avatar answered Oct 30 '22 17:10

Applekid