Solved

JPEG Compression Issue

Posted on 2008-10-10
4
943 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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