如何设置Bitmap.Width和Bitmap.height [英] How to set Bitmap.Width and Bitmap.height
问题描述
您好我已经加载了位图,我需要设置自己的高度和宽度,
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 ?
推荐答案
另一个问题确实可以为您提供一些代码。但你可能想要一个解释。
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.
这篇关于如何设置Bitmap.Width和Bitmap.height的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!