21

I have to build an application in .Net (3.5) to pick up a TIFF file saved from another piece of software and convert it into a PNG so that it can be rendered easily in Internet Explorer. Does anyone know of any libraries (preferably freeware/open source) that will do this conversion for me?

If there aren't any simple ways of getting it to a PNG are there any libraries that I can use to transform it to another IE friendly image format?

I know I can pass a TIFF to the browser and use a plugin to render it but the PCs this is aimed at are locked down and can't install plugins.

colethecoder
  • 1,139
  • 2
  • 8
  • 26

2 Answers2

38
System.Drawing.
    Bitmap.FromFile("your image.tif")
              .Save("your image.png", System.Drawing.Imaging.ImageFormat.Png);

Please, also check this: Convert Tiff Images to Gif/Jpeg

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
  • Thanks for this it worked first time, you've saved me ages of messing about. – colethecoder Oct 14 '09 at 13:49
  • 1
    Works like a charm with simplier streams :) `System.Drawing.Bitmap.FromStream(tiffStream).Save(pngStream, System.Drawing.Imaging.ImageFormat.Png);` – SandRock Jan 17 '12 at 22:47
  • 2
    @Chris I have posted an answer that does work for multi-page tiffs here: http://stackoverflow.com/a/24617585/82729 – Tom Halladay Jul 07 '14 at 18:46
8

In C# / .NET, it is probably as easy as:

using System.Drawing;
using System.Drawing.Imaging;

using (var tiff = new Bitmap("my_tiff_file.tif")) {
    tiff.Save("output.jpg", ImageFormat.Jpeg);
}

If for some reason System.Drawing.Imaging won't read your TIFF files, check out an open-source project called ImageMagick, which will read and write just about any image format imaginable. Worst case scenario you'll need to call ImageMagick's convert.exe via Process.Start() in .NET - not elegant, but it does work.

Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
  • The question specifically said "to png" though. And it's not a good idea to save to jpeg without specifying the save quality. – Nyerguds Sep 12 '17 at 11:19