PC Review


Reply
Thread Tools Rate Thread

Converting Tif to Jpeg problem

 
 
=?Utf-8?B?bWFydGlucmFqb3R0ZUBuZXdzZ3JvdXBzLm5vc3Bh
Guest
Posts: n/a
 
      5th Sep 2005
(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();
}







--
Martin Rajotte
Incycle Software
 
Reply With Quote
 
 
 
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      6th Sep 2005
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/micro...es.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.

 
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
Problem converting TIFF to JPEG =?Utf-8?B?TWFydGluIFJham90dGU=?= Microsoft Dot NET Framework 0 5th Sep 2005 06:00 PM
Problem converting TIFF to JPEG =?Utf-8?B?TWFydGluIFJham90dGU=?= Microsoft Dot NET Framework 0 26th Aug 2005 04:43 PM
Converting MAX and TIF into JPEG, JPG and/or PDF Martin Freeware 6 5th Aug 2005 10:13 PM
Re: converting jpeg to bit map Yves Alarie Windows XP Photos 0 7th May 2004 08:39 PM
Re: converting jpeg to bit map Nick Burns Windows XP Photos 0 7th May 2004 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:17 PM.