Re: resizing image quality
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.
Code:
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;
}
Re: resizing image quality
Hi, I have writen my own thumbnail algorithm using GDI+
Code:
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
Re: resizing image quality
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.