How to set Bitmap.Width and Bitmap.height

。_饼干妹妹 提交于 2019-12-10 13:49:54

问题


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 ?


回答1:


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.




回答2:


The other question will indeed help you by giving you some code. But you may want an explanation.

You can't assign to the dimensions because it wouldn't make any sense - once the image data is loaded, changing the size would require rearranging the data, inserting or removing sections of pixel data. A simple size assignment wouldn't have enough information to do this properly for you.

The proper way to change the size of an image is to create a new one, and then draw the old image onto it. For that, see the other questions that have been referenced.




回答3:


This may help you Resizing an image in asp.net



来源:https://stackoverflow.com/questions/5987249/how-to-set-bitmap-width-and-bitmap-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!