How to set Bitmap.Width and Bitmap.height

Sudantha  picture Sudantha · May 13, 2011 · Viewed 50.6k times · Source

Hi i have loaded a bitmap and i need to set my own height and width ,

bitmap.height = 100;

but this statement doesn't allow me because it says that

'System.Drawing.Image.Width' cannot be assigned to -- it is read only

whats the method to re-size the bitmap? or assign these parameters ?

Answer

Joe picture Joe · May 13, 2011

The parameters are read-only because a bitmap is a fixed size. Changing the size of the bitmap structure wouldn't do anything to affect the image. What you need is to scale the image, rather than just assign a width/height property.

There isn't a built-in method I'm aware of that will do this for you, so you'll need to go through some extra work. This tutorial may help you out.