473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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;
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 3727

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: google12 | last post by:
hi, May anyone help me? I need a lib which support .jpeg file with RGBA mode. PIL seems to support RGB and CMYK mode only... Thanks for your help.
8
by: Philip Wagenaar | last post by:
..43Hi, I am trying to extract tiff images from a multipage tiff and save them to disk. This is becoming almost a nightmare for me. I have seen several examples on the net that talk about this....
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
2
by: Ira | last post by:
Is it possible to save a JPEG file as a Tif with specifically the JPEG compression in Vb.net? If yes, how?
2
by: Asfar | last post by:
I am using GDI+ to load a tiff image and write a string to it and save the tiff image to another file. I can save the image with only LZW Compression and not abel to save with CCITT4...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
2
by: rejidasan | last post by:
Hello All, I have a MFC Dialog based application. I am not using GDI or GDI+ libraries. I need to load PNG and JPEG images in this Dialog Based application. Can you suggest me how to to do...
2
by: =?Utf-8?B?bWNpbWFnaW5n?= | last post by:
Hi, Is there any way to get . TIF, JPEG,GIF compression format. Like i have couple of images saved in my hard drive . i want to get each of these images compression format. any comments on this...
6
by: Victory | last post by:
Hi, I need to know the compression type of jpeg (jpg) files. I am using the System.Drawing.Imaging and loading the file using an Image object. The next thing i do, is to examine the propertyItems...
5
by: RobT | last post by:
I'll admit, that I don't do a lot of GDI+ programming and I'm sure this is an easy answer. I'm trying to draw a couple of shapes in a web site. I can display them just fine, but on some of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.