Converting Tif to Jpeg problem

G

Guest

(Sorry for the double post I just saw the naming required for themanged
newsgroup and I need an answer!! Thanks)
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();
}
 
P

Peter Huang [MSFT]

Hi

Based on my knowledge, .NET 1.1 used GDI+ 1.0, it did not support all kinds
of Tiff format.

Here is a link for your reference.
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_t
hread/thread/176f6a908d9b7de8/2fcde88dd74d4d97?lnk=st&q=%22v-phuang%22+tiff&
rnum=2&hl=zh-CN#2fcde88dd74d4d97

Also you may try the code on Ken's website.
http://www.bobpowell.net/addframes.htm

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top