PC Review


Reply
Thread Tools Rate Thread

Problem converting TIFF to JPEG

 
 
=?Utf-8?B?TWFydGluIFJham90dGU=?=
Guest
Posts: n/a
 
      5th Sep 2005
Hi,

I'm writing an application that extract attachment from
Exchange, save it in an SQL DB and then display it over the web. Everything
works fine for JPG, GIF, etc. However for TIFF file I need to convert them.
However my code does not seem to work... I can convert from JPEG to GIF but
not from TIFF to GIF or JPEG.

For some reason the converted TIFF image appears to become corrupted during
the conversion... The resulting JPEG image shows an empty large image
holder. If I
"re-convert" (or if you prefer "re-save as a JPEG") a second time the image
again before displaying it, then it shows a portion of the image but then
seems to repeat a "pixel row" indefinetely till the bottom... Any idea has to
what I'm doing wrong?

Thanks a lot for your help.

Here is the code I use:


//Converts the bytes extracted from the exchange attachment
//Note: I tried using a file instead of memory stream with the same results
public byte[] ConvertTiffToJpeg(byte[] tiffImage)
{

//Creating memory stream with the raw image data
System.IO.MemoryStream memStrm = new
System.IO.MemoryStream(tiffImage, true);
memStrm.Write(tiffImage, 0, tiffImage.Length);

//Create an image from the memory stream
System.Drawing.Image img =
System.Drawing.Image.FromStream(memStrm, true, false);

//Get the list of available encoders
System.Drawing.Imaging.ImageCodecInfo[] codecs =
System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();

//find the encoder with the image/jpeg mime-type
System.Drawing.Imaging.ImageCodecInfo ici = null;

foreach (System.Drawing.Imaging.ImageCodecInfo codec in
codecs)
{
if (codec.MimeType == "image/jpeg")
ici = codec;
}

//Create a collection of encoder parameters (we only need
one in the collection)
System.Drawing.Imaging.EncoderParameters ep = new
System.Drawing.Imaging.EncoderParameters();

//Create an encoder parameter for quality with an
appropriate level setting
ep.Param[0] = new
System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);


//Convert the tiff image to jpeg and save the result to a
new memory strem
System.IO.MemoryStream convertedMs = new
System.IO.MemoryStream();
img.Save(convertedMs, ici, ep);

//Convert the jpeg image back to byte
return convertedMs.ToArray();
}





 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I attach a .tiff without converting to .jpeg? Diamonds585 Microsoft Outlook Discussion 2 26th Nov 2009 02:58 AM
converting a TIFF image to JPEG, how do I do it? Frustrated... Microsoft Powerpoint 3 19th Dec 2007 07:51 PM
Problem converting TIFF to JPEG =?Utf-8?B?TWFydGluIFJham90dGU=?= Microsoft Dot NET Framework 0 26th Aug 2005 04:43 PM
CONVERTING A WMF PC IMAGE FOR USE ON MAC AS A TIFF OR JPEG - ? =?Utf-8?B?c2hlcnls?= Microsoft Frontpage 1 10th May 2005 08:11 PM
Converting Tiff To JPEG Ron Microsoft Dot NET 0 27th Sep 2003 04:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:01 AM.