Photo Nach/Main Form.cs
/// Source: https://stackoverflow.com/questions/1922040/how-to-resize-an-image-c-sharp
/// <summary>
/// Resize the image to the specified width and height.
/// </summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
/// <param name="height">The height to resize to.</param>
/// <returns>The resized image.</returns>
Resize the image to the specified width and height.
Resize the image to the specified width and height .
public static Bitmap ResizeImage(Image image, int width, int height)
        {
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);
            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighSpeed;
                graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                graphics.SmoothingMode = SmoothingMode.HighSpeed;
                graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            return destImage;
        }
public static Bitmap ResizeImage ( Image image , int width , int height ) { var destRect = new Rectangle ( 0 , 0 , width , height ) ; var destImage = new Bitmap ( width , height ) ; destImage . SetResolution ( image . HorizontalResolution , image . VerticalResolution ) ; using ( var graphics = Graphics . FromImage ( destImage ) ) { graphics . CompositingMode = CompositingMode . SourceCopy ; graphics . CompositingQuality = CompositingQuality . HighSpeed ; graphics . InterpolationMode = InterpolationMode . NearestNeighbor ; graphics . SmoothingMode = SmoothingMode . HighSpeed ; graphics . PixelOffsetMode = PixelOffsetMode . HighSpeed ; using ( var wrapMode = new ImageAttributes ( ) ) { wrapMode . SetWrapMode ( WrapMode . TileFlipXY ) ; graphics . DrawImage ( image , destRect , 0 , 0 , image . Width , image . Height , GraphicsUnit . Pixel , wrapMode ) ; } } return destImage ; }
Resize the image to the specified width and height.
Resize the image to the specified width and height .
The resized image.
The resized image .
image
Image
The image to resize.
The image to resize .
width
int
The width to resize to.
The width to resize to .
height
int
The height to resize to.
The height to resize to .