PDA

Click to See Complete Forum and Search --> : resizing image quality


Techno
Jul 11th, 2006, 09:56 PM
I am trying to take a screen shot of the screen. This is easily done.
What I want to do now is resize it, without effecting the quality much or rather should i say, somehow keeping the image visable or clear enough.

I know how to resize the image in C#. I am saving it to a JPG format (file size is an important aspect here).
However, I am wondering if there is a way to make the image clearer?

Resizing image (down to) 640x480.

Any tips/tricks are much appreciated on trying to make the image still clear/viewable.

jmcilhinney
Jul 11th, 2006, 10:33 PM
I guess that the easiest way would be to call GetThumbnailImage on the full image. That may not be the most efficient way to do it but the end result will be as clear as possible I'd guess.private bool GetThumbnailImageAbort()
{
return false;
}

private void Form1_Load(object sender, EventArgs e)
{
Image fullImage = Image.FromFile(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures ),
"screenshot.bmp"));
Image thumbImage = fullImage.GetThumbnailImage(640,
480,
new Image.GetThumbnailImageAbort(this.GetThumbnailImageAbort),
IntPtr.Zero);

this.pictureBox1.Image = thumbImage;
}

RohanWest
Jul 12th, 2006, 11:03 AM
Hi, I have writen my own thumbnail algorithm using GDI+


public class Thumbnail
{
public Thumbnail()
{
}

public static Image Create(string filename, int width, int height)
{
Image image = Image.FromFile(filename);
return Create(image,width,height);
}

public static Image Create(Stream stream, int width, int height)
{
Image image = Image.FromStream(stream);
return Create(image,width,height);
}

public static Image Create(Image image, int width, int height)
{
Image thumb = new Bitmap(width,height);
double largestRatio = Math.Max(image.Width/width,image.Height/height);

Graphics g = Graphics.FromImage(thumb);
g.FillRectangle(Brushes.White,0,0,width,height);

g.InterpolationMode = InterpolationMode.HighQualityBicubic;

float thumbWidth = (float)(image.Width * (1.0 / largestRatio));
float thumbHeight = (float)(image.Height * (1.0 / largestRatio));
float x = (float)((width / 2) - (thumbWidth / 2));
float y = (float)((height / 2) - (thumbHeight / 2));

g.DrawImage(image,x,y,thumbWidth,thumbHeight);
g.Dispose();

return thumb;
}
}


By changing the InterpolationMode you will see a difference in the quality of output! Each algorithm has a diiferent degree of overheads!

This produces image similar to the Windows Thumbnail

Hope this helps

Rohan

mendhak
Jul 12th, 2006, 02:54 PM
Nice algo, does it work for transparent gifs as well? I've always used a method that's the 'simplest way out', and has often caused problems when it comes to resizing transparent gifs.