Solved

JPEG Compression Issue

Posted on 2008-10-10
4
935 Views
Last Modified: 2013-11-08
Hello, I am changing the default compression set on an jpeg using the following code:

                    'Setup a JPEG codec with desired quality
                    Dim Codec, JPEGCodec As System.Drawing.Imaging.ImageCodecInfo
                    Dim EncParams As System.Drawing.Imaging.EncoderParameters

                    For Each Codec In System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders
                        If Codec.MimeType = "image/jpeg" Then
                            JPEGCodec = Codec
                            Exit For
                        End If
                    Next 'Supposedly this cannot fail as image/jpg is built-in to GDI+ encoders

                    EncParams = New System.Drawing.Imaging.EncoderParameters(1)
                    EncParams.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, imageCompression)

                    HttpContext.Current.Response.ContentType = "image/jpeg"
                    outputImage.Save(HttpContext.Current.Response.OutputStream, JPEGCodec, EncParams)
                    'outputImage.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

It works great but not in IE6.  The browser just crashes.  When I uncomment the last line an comment out the line before the last it work fine.  Is there a way to fix this or is there another way to change the default compression applied to an image when it is saved?

Thanks
0
Comment
Question by:grogo21
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
saleek earned 500 total points
ID: 22685054
hi,

what are you setting compression quality to?

For example, is it something like:

Dim imageCompression as Long = 99L  <-- 99 is quality percentage you would like

I dont see why IE6 would crash, if the aspx page outputs a valid bitmap then there should be no issue.

Does it work in IE7?

regards,

saleek
0
 

Author Comment

by:grogo21
ID: 22688602
Hello,
Yes I am using something like Dim imageCompression as Long = 99L.

I don't see why it would crash either. It works on IE7 and all other browsers.  For now I am using the following to get around it:

                    If HttpContext.Current.Request.UserAgent.Contains("MSIE 6") Then
                        outputImage.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Else
                    outputImage.Save(HttpContext.Current.Response.OutputStream, JPEGCodec, EncParams)
                    End If

I did use fiddler and the responses were identical with and without compression.  IE6 just crashes for some reason when I use a custom compression.  Is this something I can fix.  It seems to be an issue with the browser.

THanks
0
 

Author Comment

by:grogo21
ID: 22688872
Actually If I comment out this line flater in my code I can use compression just fine in IE6:

            'HttpContext.Current.Response.Close()

Any ideas why?

Thanks
0
 
LVL 11

Expert Comment

by:saleek
ID: 22794111
No - but I I have no idea why you would close the response.

Perhaps IE could not load the image (compress it?) beore you closed the response.

All the best.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question