Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 947
  • Last Modified:

JPEG Compression Issue

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
grogo21
Asked:
grogo21
  • 2
  • 2
1 Solution
 
Ramesh SrinivasTechnical ConsultantCommented:
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
 
grogo21Author Commented:
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
 
grogo21Author Commented:
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
 
Ramesh SrinivasTechnical ConsultantCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now