Esempio n. 1
0
        private void CreateSizedImage(System.Drawing.Image image, ImageSize targetSize, string targetPath)
        {
            var       imageComparer = new ImageComparer(image, targetSize);
            ImageSize newImageSize  = null;

            newImageSize = imageComparer.IsLandscape ? imageComparer.LandscapeSize : imageComparer.PortraitSize;

            using (var bitmap = new Bitmap(newImageSize.Width, newImageSize.Height, PixelFormat.Format24bppRgb))
            {
                bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    graphics.DrawImage(image,
                                       new Rectangle(0, 0, newImageSize.Width, newImageSize.Height),
                                       new Rectangle(0, 0, image.Width, image.Height),
                                       GraphicsUnit.Pixel);
                }

                bitmap.Save(targetPath, ImageFormat.Jpeg);
            }
        }
Esempio n. 2
0
        private void CreateSizedImage(System.Drawing.Image image, ImageSize targetSize, string targetPath)
        {
            var imageComparer = new ImageComparer(image, targetSize);
            ImageSize newImageSize = null;

            newImageSize = imageComparer.IsLandscape ? imageComparer.LandscapeSize : imageComparer.PortraitSize;

            using (var bitmap = new Bitmap(newImageSize.Width, newImageSize.Height, PixelFormat.Format24bppRgb))
            {
                bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    graphics.DrawImage(image,
                        new Rectangle(0, 0, newImageSize.Width, newImageSize.Height),
                        new Rectangle(0, 0, image.Width, image.Height),
                        GraphicsUnit.Pixel);
                }

                bitmap.Save(targetPath, ImageFormat.Jpeg);
            }
        }