Exemple #1
0
        public static Image Thumbnail(Image source, int width, int height)
        {
            int    num  = source.Width;
            int    num2 = source.Height;
            double num3 = (double)width / (double)source.Width;
            double num4 = (double)height / (double)source.Height;
            double num5 = (num3 > num4) ? num3 : num4;

            num  = Convert.ToInt32((double)source.Width * num5);
            num2 = Convert.ToInt32((double)source.Height * num5);
            num  = ((num >= source.Width) ? source.Width : num);
            num2 = ((num2 >= source.Height) ? source.Height : num2);
            Bitmap   bitmap   = new Bitmap(num, num2);
            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.InterpolationMode = InterpolationMode.High;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;
            graphics.DrawImage(source, 0, 0, num, num2);
            graphics.Dispose();
            return(ImageTo.Cute(bitmap, (bitmap.Width - width) / 2, (bitmap.Height - height) / 2, width, height));
        }