[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Kevin Marshall

11/13/2004 10:44:00 PM

I am using the following code to create a thumbnail of a jpg image, its
works but the quality of the resulting image is not very good, if I do the
same thing in a graphics program like fireworks its much better, does anyone
know how to get .NET to make better quality images, it does not matter what
values I set for the EncoderParameters or even when I don't use the
EncoderParameters at all, the result is always the same with no difference
at all.

Bitmap Bmp = new Bitmap(OriginalImg, TheSize);
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
EncoderParameters ep=new EncoderParameters(3);
ep.Param[0]=new EncoderParameter(Encoder.Quality, (long)100);
ep.Param[1]=new EncoderParameter(Encoder.Compression, (long)0);
ep.Param[2]=new EncoderParameter(Encoder.ColorDepth, 24L);
Bmp.Save(Path,ici,ep);

Thanks in advance.

--
Kevin Marshall
WebXeL.com Ltd
http://www....

ASP.NET Dreamweaver Extensions
http://www.webxe...


4 Answers

Bill Woodruff

11/14/2004 3:43:00 AM

0

Kevin,

A few ideas. Caveat : I have not played with the System.Drawing.Imaging
namespace, though it looks like the ImageAttributes object of that namespace has
some settings that might influence drawing quality.

Have you tried using GDI+ DrawImage operator and manipulating settings like :
InterpolationMode, CompositingQuality, PixelOffsetMode, SmoothingMode, etc. off
the Graphics object of the System.Drawing namespace ?

Bob Powell has lots of good code and comments on his GDI+ FAQ which you can link
to by opening any of the many messages from the ever-prolific Bob here on this
newsgroup,

Alex Hilyard wrote an interesting article (with graphic examples of differences
in image quality when the quality settings are varied) :

http://www.devx.com/dotnet/Art...

That has a number of interesting techniques for image resizing.

best, Bill Woodruff
dotScience
Chiang Mai, Thailand


Bob Powell

11/14/2004 11:12:00 AM

0

When creating the bitmap using the original and size in the way you've done
here the bitmap seems to be created using a nearest-neigbour sampling of the
original so much of the image information is lost.

For really nice thumbnails do the following...

Bitmap bm=new Bitmap(thumnailSizeX, thumbnailSize.Y);
Graphics g=Graphics.FromImage(bm);
g.InterpolationMode=InterpolationMode.HighQualityBilinear;
g.DrawImage(original, new Rectangle(0,0,bm.Width,
bm.Height),0,0,original.Width, original.Height,GraphicsUnit.Pixel);
g.Dispose();
//save bm here with the new thumbnail...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Kevin Marshall" <admin@webxelonline.com> wrote in message
news:ekO%238IdyEHA.3976@TK2MSFTNGP09.phx.gbl...
> I am using the following code to create a thumbnail of a jpg image, its
> works but the quality of the resulting image is not very good, if I do the
> same thing in a graphics program like fireworks its much better, does
anyone
> know how to get .NET to make better quality images, it does not matter
what
> values I set for the EncoderParameters or even when I don't use the
> EncoderParameters at all, the result is always the same with no difference
> at all.
>
> Bitmap Bmp = new Bitmap(OriginalImg, TheSize);
> ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
> ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
> EncoderParameters ep=new EncoderParameters(3);
> ep.Param[0]=new EncoderParameter(Encoder.Quality, (long)100);
> ep.Param[1]=new EncoderParameter(Encoder.Compression, (long)0);
> ep.Param[2]=new EncoderParameter(Encoder.ColorDepth, 24L);
> Bmp.Save(Path,ici,ep);
>
> Thanks in advance.
>
> --
> Kevin Marshall
> WebXeL.com Ltd
> http://www....
>
> ASP.NET Dreamweaver Extensions
> http://www.webxe...
>
>


Kevin Marshall

11/14/2004 12:20:00 PM

0

Thanks guys, I will let you know how I get on :)

--
Kevin Marshall
WebXeL.com Ltd
http://www....

ASP.NET Dreamweaver Extensions
http://www.webxe...
"Kevin Marshall" <admin@webxelonline.com> wrote in message
news:ekO%238IdyEHA.3976@TK2MSFTNGP09.phx.gbl...
>I am using the following code to create a thumbnail of a jpg image, its
>works but the quality of the resulting image is not very good, if I do the
>same thing in a graphics program like fireworks its much better, does
>anyone know how to get .NET to make better quality images, it does not
>matter what values I set for the EncoderParameters or even when I don't use
>the EncoderParameters at all, the result is always the same with no
>difference at all.
>
> Bitmap Bmp = new Bitmap(OriginalImg, TheSize);
> ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
> ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
> EncoderParameters ep=new EncoderParameters(3);
> ep.Param[0]=new EncoderParameter(Encoder.Quality, (long)100);
> ep.Param[1]=new EncoderParameter(Encoder.Compression, (long)0);
> ep.Param[2]=new EncoderParameter(Encoder.ColorDepth, 24L);
> Bmp.Save(Path,ici,ep);
>
> Thanks in advance.
>
> --
> Kevin Marshall
> WebXeL.com Ltd
> http://www....
>
> ASP.NET Dreamweaver Extensions
> http://www.webxe...
>


Kevin Marshall

11/14/2004 1:31:00 PM

0

Thanks Bob, that did the trick :)

--
Kevin Marshall
WebXeL.com Ltd
http://www....

ASP.NET Dreamweaver Extensions
http://www.webxe...