C# Creating thumbnail (low quality and big size problem)

Posted by ile on Stack Overflow See other posts from Stack Overflow or by ile
Published on 2010-05-18T13:47:52Z Indexed on 2010/05/18 13:50 UTC
Read the original article Hit count: 208

Filed under:
|
|
|
|
public void CreateThumbnail(Image img1, Photo photo, string targetDirectoryThumbs)
        {
            int newWidth = 700;
            int newHeight = 700;
            double ratio = 0;

            if (img1.Width > img1.Height)
            {
                ratio = img1.Width / (double)img1.Height;
                newHeight = (int)(newHeight / ratio);
            }
            else
            {
                ratio = img1.Height / (double)img1.Width;
                newWidth = (int)(newWidth / ratio);
            }

            Image bmp1 = img1.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
            bmp1.Save(targetDirectoryThumbs + photo.PhotoID + ".jpg");

            img1.Dispose();
            bmp1.Dispose();
        }

I've put 700px so that you can have better insight of the problem. Here is original image and resized one.

Any good recommendation?

Thanks,
Ile

© Stack Overflow or respective owner

Related posts about c#

Related posts about image