Results 1 to 4 of 4

Thread: resizing image quality

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Talking 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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width