Pls. suggest how to set an image's width & Height Property while saving Images
Asked
Active
Viewed 5,085 times
-1
-
2You really need to provide more context here. What APIs are you using, for example? – madd0 Mar 08 '11 at 12:19
1 Answers
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