Re: Resizing Images
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Mar 2009 12:35:59 -0700
On Mon, 30 Mar 2009 12:07:26 -0700, <dj1072@xxxxxxxxx> wrote:
I am trying to write a C# console application that resizes images and
copies them to a new folder.
I am resizing them by creating a new bitmap object and saving it out
as an image (at zero compression, full quality).
I can get the image to resize fine, but the image quality is bad
(badly pixelated with lots of artifacts). Google searching has shown
that this has to do with the downsampling that .NET uses and that it's
unavoidable.
Has shown? How? Do you have any specific links that actually say that? It's surprising that with all that Googling, you managed to miss previous discussions in this newsgroup about the topic in which the opposite has been shown.
Is that the truth? Is there no way to get a crisp, near-original-
quality JPEG output from the .NET framework? [...]
If you are resizing an image, some loss of quality is inevitable. Not even Photoshop can avoid it. Reducing the size of an image will necessarily cause a loss of information, and increasing the size of an image will necessarily result in an image for which the full resolution of the output image is not taken advantage of.
Even the default resizing algorithm in .NET does what I think is a reasonable job. However, you can control the type of resizing algorithm by creating a new empty Bitmap instance and drawing the old one into the new one after setting the interpolation mode to whatever you want. For example:
Image ResizeImage(Image imageOriginal, Size sizeNew)
{
Image imageRet = new Bitmap(sizeNew.Width, sizeNew.Height, imageOriginal.PixelFormat);
using (Graphics gfx = Graphics.FromImage(imageRet))
{
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.DrawImage(imageOriginal, 0, 0, sizeNew.Width, sizeNew.Height);
}
return imageRet;
}
If that approach doesn't address your requirements, you need to be much more specific about what it is you're trying to do, how you're doing it now, and what about the results are unacceptable to you. That includes the exact code you're using to resizing the image, what sizes you're dealing with, what the original image data looks like, the exact code you're using to save the image, and what specifically is wrong with the output image.
Pete
.
- Follow-Ups:
- Re: Resizing Images
- From: dj1072
- Re: Resizing Images
- References:
- Resizing Images
- From: dj1072
- Resizing Images
- Prev by Date: Resizing Images
- Next by Date: Code my own xml intellisense
- Previous by thread: Resizing Images
- Next by thread: Re: Resizing Images
- Index(es):
Relevant Pages
|