Link to home
Start Free TrialLog in
Avatar of SkipFire
SkipFire

asked on

Convert TIF to JPG

I think the following code "should" work, the output is about the right size for a jpg, but it is not coming out as a valid jpg image file.  I have tried saving to disk as well.  Please either tell me how to fix this code, or give me a good sample that does not use third-party objects.  I am working in .NET 2.0.  I have verified permissions are NOT a problem.  C# code solutions are fine as well.  ---page editor please do not move this to VB.NET.
 
        Dim originalimage As System.Drawing.Image = System.Drawing.Image.FromFile("C:\Test.tif")
        Dim stm As New System.IO.MemoryStream
        Call originalimage.Save(stm, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim bytes(stm.Length) As Byte
        Call stm.Read(bytes, 0, stm.Length - 1)
        Response.ContentType = "image/jpeg"
        Call Response.Clear()
        Call Response.BinaryWrite(bytes)
        Call originalimage.Dispose()
        originalimage = Nothing
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SkipFire
SkipFire

ASKER

Beautiful - it worked great.
Thanks.  Short and sweet exchange!