Setting JPEG-quality on image 
Author Message
 Setting JPEG-quality on image
Hi!

I want to control JPEG-quality on an image, I resize. How do I do that on
the below very simple code?
[Snip]
Dim objSourceImage As System.Drawing.Image
objSourceImage = System.Drawing.Image.FromFile("C:\temp\WaterLilies.jpg")
Dim objImageVariant As New Bitmap(objSourceImage, New Size(300, 300))
objImageVariant.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
[Snip]

I have gone through googlegroups to find examples of how to set jpeg-quality
on an image. I found some pseudo-code, some C# and I have tried for hours
and hours to make it work - with no luck. I know the solution is to use
ImageCodecInfo and the EncoderParameter(s) - but how? I would really
appreciate, if someone could show me, how it's done.

Here are some snippets from my experiments:

Dim objImageCodecInfo() As ImageCodecInfo

objImageCodecInfo = ImageCodecInfo.GetImageEncoders
Dim objEncoderParameters As EncoderParameters
objEncoderParameters = objImageVariant.GetEncoderParameterList()
Dim objEncoderParameter As New EncoderParameter(Encoder.Quality, 70) 'The
quality I want
objEncoderParameters.Param(0) = objEncoderParameter
objImageVariant.Save(Response.OutputStream, objImageCodecInfo(1),
objEncoderParameters)

Thanks in advance

Klaus Jensen



Fri, 09 Jul 2004 22:24:17 GMT  
 Setting JPEG-quality on image
I found the answer myself... :) Weird, I fought with this code for hours
yesterday... Anyway, this works:

[code]
Dim objSourceImage As System.Drawing.Image

objSourceImage = System.Drawing.Image.FromFile("C:\temp\WaterLilies.jpg")

Dim objImageVariant As New Bitmap(objSourceImage, New Size(300, 300))

Dim objImageCodecInfo() As ImageCodecInfo

objImageCodecInfo = ImageCodecInfo.GetImageEncoders

Dim objEncParams As New EncoderParameters(1)

Dim objEncParam As New EncoderParameter(Encoder.Quality, 10)

objEncParams.Param(0) = objEncParam

objImageVariant.Save(Response.OutputStream, objImageCodecInfo(1),
objEncParams)
[code]

- Klaus Jensen



Fri, 09 Jul 2004 23:07:51 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Picture or Image ctrl - image quality

2. How to retrieve still Jpeg images from Jpeg AVI File

3. load a Jpeg image into a picturebox or image control

4. Quality Product - Quality Support

5. poor TIFF image quality

6. Save/Retrieve Image from Database (quality issue)

7. High Quality Image resizing HOW ?

8. Image Box Picture Quality

9. jpg image quality in vb5 picture control

10. Toolbar image quality poor from bitmaps

11. Print Quality Images

12. Print-Quality Images

 

 
Powered by phpBB® Forum Software