469,282 Members | 1,945 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

GDI+ Error - problem with JPEG compression in Multi-page tiffs

I have multi-page tiff files. I need to extract individual frames from the
multi-page tiffs and save them as single-page tiffs. 95% of the time I
receive multi-page tiffs containing 1 or more black and white CCITT4
compressed files (frames) inside the tiff. Every now and then I receive a
mixture of black and white CCITT4 and JPEG compressed files, and sometimes
just multi-page tiffs with JPEG only. The code runs great when dealing with
the CCITT4 compressed files but fails every time it encounters a JPEG
compressed file (frame). I am using GDI+ and the System.Drawing and
System.Drawing.Imaging namespaces. The only bit of info I’ve found regarding
this problem was a single sentence stating ‘some methods in GDI+ don’t work
on JPEG and GIF files.’ Not very helpful. Here is the code.

The method ProcessDocument receives a string array containing the path to
the multi-page tiffs on the network.

Any leads would be greatly appreciated! I am lost...

private void ProcessDocument(string documentNumber, string[] pageFiles)
{
forUpload = true;
ArrayList images = null;
try
{
int pageIndex = -1;
images = new ArrayList();
foreach (string imageFilePath in pageFiles)
{
filePath = imageFilePath;
Bitmap image = null;
Guid g;
FrameDimension imgFrameDim;
int imgFrameCount = 0;
try
{
// Path to file containing multi-page tiff
// Will fail if multi-page tiff contains a single JPEG compressed frame
// Will continue if multi-page tiff contains more than 1 frame and the //
first is a CCITT4 compressed frame
image = new Bitmap(imageFilePath);
g = image.FrameDimensionsList[0];
imgFrameDim = new FrameDimension(g);
imgFrameCount = image.GetFrameCount(imgFrameDim);
}
catch (Exception exc)
{
// bad image file (corrupt or JPEG)
// Write to log
}
for (int frameIx = 0; frameIx < imgFrameCount; frameIx++)
{
try
{
// SelectActiveFrame works great if CCITT4, LZW, and other // compressed
frames
// An exception occurs as soon as it encounters JPEG
image.SelectActiveFrame(imgFrameDim, frameIx);
pageIndex++;
int pageNumber = pageIndex + 1; // not zero based
IO.Stream str = new System.IO.MemoryStream();
image.Save(str, ImageFormat.Tiff);
Bitmap pageImage = new Bitmap(str);
images.Add(pageImage);
}
catch (Exception exc)
{
forUpload = false;
// Write to the log
}
}
image.Dispose();
}
}
catch (Exception exc)
{
throw new AppEx("Error processing: " + documentNumber, exc);
}
}

Jul 21 '05 #1
0 3257

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Philip Wagenaar | last post: by
2 posts views Thread by Asfar | last post: by
2 posts views Thread by =?Utf-8?B?bWNpbWFnaW5n?= | last post: by
6 posts views Thread by Victory | last post: by
5 posts views Thread by RobT | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.