views:

81

answers:

3

I am able to convert a single page TIFF to a PNG in .Net, however, how would I do this for a multipage TIFF?

A: 

Off the top of my head, You would load two (or more) tiffs (like you are already doing for one) and then you will have to combine them into a bigger image (this might be a little work, but shouldn't be anything crazy). once you have the big tiff, convert it to png (like you are already doing).

Tony Abrams
A: 

Imagemagick can do just about anything with images but it might take a while to get it right due to the overwhelming amount of options to choose from. You can use interop to work directly with Imagemagick or you can use a .NET wrapper. I have only used interop so I don't know how good or bad the wrapper is.

private readonly ImageMagickObject.MagickImageClass _imageMagick = new ImageMagickObject.MagickImageClass();

var parameters = new object[] {sourcePath, destPath};
_imageMagick.Convert(ref parameters);

The parameters you'll have to find out for yourself on the ImageMagick website. Look at the help for the command line parameter and search the forum for multipage tiff. I assume you want to split the tiff into multiple pngs? Then maybe something like this:

convert multipage.tif single%d.png

Daniel Lee
+2  A: 

You should select active frame (page) in a loop and convert each tiff page to a png.

int pageCount = 1;
try
{
    pageCount = bmp.GetFrameCount(FrameDimension.Page);
}
catch (Exception)
{
    // sometimes GDI+ throws internal exceptions.
    // just ignore them.
}

for (int page = 0; page < pageCount; page++)
{
    bmp.SelectActiveFrame(FrameDimension.Page, page);
    // save or otherwise process tiff page
}

This code assumes that you can load Tiff image in System.Drawing.Bitmap object.

Bobrovsky
very cool, that worked like a charm
mytwocents