Exemple #1
0
        public static Image Zoom(Image source, int percent)
        {
            int width  = source.Width * percent / 100;
            int height = source.Height * percent / 100;

            return(ImageTo.Zoom(source, width, height));
        }
Exemple #2
0
        public static Image Zoom(Image source, int width, int height, bool isDeformation)
        {
            Image result;

            if (isDeformation)
            {
                result = ImageTo.Zoom(source, width, height);
            }
            else
            {
                double num  = (double)width / (double)source.Width;
                double num2 = (double)height / (double)source.Height;
                double num3 = (num > num2) ? num : num2;
                int    num4 = Convert.ToInt32((double)source.Width * num3);
                int    num5 = Convert.ToInt32((double)source.Height * num3);
                num4 = ((num4 >= source.Width) ? source.Width : num4);
                num5 = ((num5 >= source.Height) ? source.Height : num5);
                Bitmap   bitmap   = new Bitmap(width, height);
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.Clear(Color.White);
                graphics.DrawImage(source, (width - num4) / 2, (height - num5) / 2, num4, num5);
                graphics.Dispose();
                result = bitmap;
            }
            return(result);
        }