Exception while reading multiframe TIFF containing different imageformats

  • Thread starter sascha.folville
  • Start date
S

sascha.folville

Hi,

I've some trouble reading the containing frames of a multiframe tiff.
First frame is a 1700X2400 px CCITT4, second in JPG 820x1200, third is
a CCITT again ... and so on.

My function extracts the CCITT-frames correct, but the second, fourth,
etc. frames causes a general GDI+ error.

Hope someone can help!

Sascha

Here is my code:

public Image GetFrame(int frameNumber)
{
System.Drawing.Image image=Image.FromFile(_ImageFileName,true);

MemoryStream ms=null;
Image retImage=null;
try
{
ms=new MemoryStream();
Guid objGuid=image.FrameDimensionsList[0];
FrameDimension objDimension=new FrameDimension(objGuid);

image.SelectActiveFrame(objDimension,frameNumber);
image.Save(ms,ImageFormat.Bmp);

retImage=Image.FromStream(ms);

return retImage;
}
catch (Exception ex)
{
if (ms!=null)
{
ms.Close();
}
if (retImage!=null)
{
retImage.Dispose();
}
throw;
}
}
 
A

Adrian Gallero

Hi,
I've some trouble reading the containing frames of a multiframe tiff.
First frame is a 1700X2400 px CCITT4, second in JPG 820x1200, third is
a CCITT again ... and so on.

While I can't help directly on the issue, I have had similar problems
with GDI+ and multipage tiffs. The main issue being that GDI+ loads the
full image in memory (all the pages) and this can lead to out of of
memory errors on big files (say a hundred of pages)

Personally in my own apps I switched to freeimage
http://freeimage.sourceforge.net/

and all those issues dissapeared.

Might be an idea.
Best regards,
Adrian.
 
S

sascha.folville

Hi, thanks for your answer,
but I don't think its a memory problem, because only every second
image has this problem.

Sascha
 
J

Jay Riggs

Hi,

I've some trouble reading the containing frames of a multiframe tiff.
First frame is a 1700X2400 px CCITT4, second in JPG 820x1200, third is
a CCITT again ... and so on.

My function extracts the CCITT-frames correct, but the second, fourth,
etc. frames causes a general GDI+ error.

Hope someone can help!

Sascha

Here is my code:

public Image GetFrame(int frameNumber)
{
System.Drawing.Image image=Image.FromFile(_ImageFileName,true);

MemoryStream ms=null;
Image retImage=null;
try
{
ms=new MemoryStream();
Guid objGuid=image.FrameDimensionsList[0];
FrameDimension objDimension=new FrameDimension(objGuid);

image.SelectActiveFrame(objDimension,frameNumber);
image.Save(ms,ImageFormat.Bmp);

retImage=Image.FromStream(ms);

return retImage;
}
catch (Exception ex)
{
if (ms!=null)
{
ms.Close();
}
if (retImage!=null)
{
retImage.Dispose();
}
throw;
}
}

Sascha,

I created a multipage tiff with alternating jpeg pages and in a small
test program used your function to successfully return an Image
object.

Could the problem be the way you're (if you're doing it) creating the
tiffs?

The program I used to create tiffs can be found here:
http://www.bobpowell.net/generating_multipage_tiffs.htm

The program I modified to use your function can be found here:
http://www.bobpowell.net/addframes.htm


Is there a specific line in your function that's throwing the error?


-Jay
 
S

sascha.folville

I've some trouble reading the containing frames of a multiframe tiff.
First frame is a 1700X2400 px CCITT4, second in JPG 820x1200, third is
a CCITT again ... and so on.
My function extracts the CCITT-frames correct, but the second, fourth,
etc. frames causes a general GDI+ error.
Hope someone can help!

Here is my code:
public Image GetFrame(int frameNumber)
{
System.Drawing.Image image=Image.FromFile(_ImageFileName,true);
MemoryStream ms=null;
Image retImage=null;
try
{
ms=new MemoryStream();
Guid objGuid=image.FrameDimensionsList[0];
FrameDimension objDimension=new FrameDimension(objGuid);
image.SelectActiveFrame(objDimension,frameNumber);
image.Save(ms,ImageFormat.Bmp);
retImage=Image.FromStream(ms);

return retImage;
}
catch (Exception ex)
{
if (ms!=null)
{
ms.Close();
}
if (retImage!=null)
{
retImage.Dispose();
}
throw;
}
}

Sascha,

I created a multipage tiff with alternating jpeg pages and in a small
test program used your function to successfully return an Image
object.

Could the problem be the way you're (if you're doing it) creating the
tiffs?

The program I used to create tiffs can be found here:http://www.bobpowell.net/generating_multipage_tiffs.htm

The program I modified to use your function can be found here:http://www.bobpowell.net/addframes.htm

Is there a specific line in your function that's throwing the error?

-Jay

Hi Jay,

the error occurs at
"image.SelectActiveFrame(objDimension,frameNumber); ".
The TIFF is not created by myself. I get it and have to work with it.
But now I found out, that the ordinary windows-fax-viewer has the same
problem. On my workstation such images are opened with Microsoft
Office Document Imaging Viewer by default ... so I didnt see the
problem that way.

Sascha
 
S

sascha.folville

Hi ng,

I've got the answer from Micosoft: GDI+ does not support Jpeg
compression of TIFF files.

So, I have to search for another lib.

Sascha
 
B

Bob Powell [MVP]

I don't know if it works but have you tried FreeImage??

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


in message news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top