[Mono-list] Convert TIFFs to PNGs

Fabian Luque Fabian Luque <fabianluque@gmail.com>
Thu, 10 Mar 2005 20:42:14 -0300


Hi people:

I've been doing some tests for a webapp I'm developing. What I'm
trying to do is convert some B&W (1 bit) TIFFs to PNGs, to view them
on a browser.

Here's the code I'm using:

//Open TIFF and save to PNG
Bitmap original = new Bitmap("00000003.TIF");

original.Save("03.png", ImageFormat.Png);



//Resize and save to PNG
Image thumb = original.GetThumbnailImage(original.Width,
original.Height, null, IntPtr.Zero);

EncoderParameters ep = new EncoderParameters();

ep.Param[0] = new EncoderParameter(Encoder.ColorDepth, 1);

thumb.Save("03thumb.png", GetEncoder("image/png"), ep);


private static System.Drawing.Imaging.ImageCodecInfo GetEncoder(string mimeType)

{

	ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();



	foreach(ImageCodecInfo codec in codecs)

		if(codec.MimeType == mimeType)

			return codec;


}


In .NET on Windows, I get this:

03.png - 84 KB - 1 bit
03thumb.png - 320 KB - 32 bits

In Mono on Linux (NLD), I get this:

03.png - 180 KB - 32 bit
03thumb.png -  180 KB - 32 bits

In .NET it's a know issue that the PNG Encoder is not working or at
least it's not configurable when saving images.

In Mono, I'm getting a bigger filesize when opening and saving the
image to another format, and also a different ColorDepth. And it seems
it always save 32 bits PNGs.

I need to be able to save a TIFF image with and without resizing to a PNG image.

Any hints?

Thanks,

-- 
Fabian Luque
http://www.forumnet.com.ar/blog