c# resize bitmap

C#
//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;
}

Source

Also in C#: