Image.FromFile(@\"path\\filename.tif\")
or
Image.FromStream(memoryStream)
both produce image objects with only on
bitmap.Dispose();
After For loop you need to Dispose bitmap. Otherwise you get error "file using other process" when try to use same file in other process.
Here's what I use:
private List<Image> GetAllPages(string file)
{
List<Image> images = new List<Image>();
Bitmap bitmap = (Bitmap)Image.FromFile(file);
int count = bitmap.GetFrameCount(FrameDimension.Page);
for (int idx = 0; idx < count; idx++)
{
// save each frame to a bytestream
bitmap.SelectActiveFrame(FrameDimension.Page, idx);
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
// and then create a new Image from it
images.Add(Image.FromStream(byteStream));
}
return images;
}
I was able to handle the multi-frame tiff by using the below method.
Image multiImage = Image.FromFile(sourceFile);
multiImage.Save(destinationFile, tiff, prams);
int pageCount = multiImage.GetFrameCount(FrameDimension.Page);
for (int page = 1; page < pageCount; page++ )
{
multiImage.SelectActiveFrame(FrameDimension.Page,page);
multiImage.SaveAdd(dupImage,prams);
}
multiImage.SaveAdd(newPage, prams);
multiImage.Dispose();
I have not tried the solution in .net 2.0 but MSDN shows the class members to exist. It did fix my problem in .net 4.5.2.