471,612 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,612 software developers and data experts.

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;
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
0 3468

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 XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.