|
-
Jul 11th, 2006, 09:56 PM
#1
Thread Starter
PowerPoster
resizing image quality
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.
-
Jul 11th, 2006, 10:33 PM
#2
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;
}
Last edited by jmcilhinney; Jul 11th, 2006 at 10:40 PM.
-
Jul 12th, 2006, 11:03 AM
#3
Addicted Member
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
You dont need eyes to see, you need vision.
-
Jul 12th, 2006, 02:54 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|