-1

Pls. suggest how to set an image's width & Height Property while saving Images

Jackson Pope
  • 14,520
  • 6
  • 56
  • 80
user633558
  • 15
  • 2
  • 3

1 Answers1

4

If you want to save bitmap with some specific width and height (which differ from the Width and Height properties of the bitmap), you need to create a new Bitmap of corresponding size and draw the initial bitmap in needed size on it.

Like this:

using (Bitmap bmpToSave = new Bitmap(1000, 500)) {
    using (Graphics g = Graphics.FromImage(bmpToSave)) {
        g.DrawImage(bmp, 0, 0, 1000, 500);
    }
    bmpToSave.Save(@"bitmap.bmp");
}

Where bmp is your original bitmap. Also, read up on some options that affect the quality of resampling if you need the high quality result.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Dyppl
  • 12,161
  • 9
  • 47
  • 68