C# Bitmap resize code example

Example 1: c# resize bitmap

//Size of "testimage.bmp" file is 1024x1024.
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\testimage.bmp");
Bitmap newImage = ResizeBitmap(bmp, 512, 512);

public Bitmap ResizeBitmap(Bitmap bmp, int width, int height)
{
    Bitmap result = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage(result))
    {
        g.DrawImage(bmp, 0, 0, width, height);
    }
 
    return result;
}

Example 2: resize image c#

public static Image resizeImage(Image imgToResize, Size size)
    {
       return (Image)(new Bitmap(imgToResize, size));
    }

    yourImage = resizeImage(yourImage, new Size(50,50));