By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

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

P: n/a
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;
int pageIndex = -1;
images = new ArrayList();
foreach (string imageFilePath in pageFiles)
filePath = imageFilePath;
Bitmap image = null;
Guid g;
FrameDimension imgFrameDim;
int imgFrameCount = 0;
// 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++)
// SelectActiveFrame works great if CCITT4, LZW, and other // compressed
// An exception occurs as soon as it encounters JPEG
image.SelectActiveFrame(imgFrameDim, frameIx);
int pageNumber = pageIndex + 1; // not zero based
IO.Stream str = new System.IO.MemoryStream();
image.Save(str, ImageFormat.Tiff);
Bitmap pageImage = new Bitmap(str);
catch (Exception exc)
forUpload = false;
// Write to the log
catch (Exception exc)
throw new AppEx("Error processing: " + documentNumber, exc);

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.