如何设置 Bitmap.Width 和 Bitmap.height
您好,我已经加载了一个位图,我需要设置自己的高度和宽度,
bitmap.height = 100;
但是这个语句不允许我,因为它说
'System.Drawing.Image.Width' cannot be assigned to -- it is read only
重新调整位图大小的方法是什么?或分配这些参数?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些参数是只读的,因为位图是固定大小的。更改位图结构的大小不会对图像产生任何影响。您需要的是缩放图像,而不仅仅是分配宽度/高度属性。
据我所知,没有内置方法可以为您执行此操作,因此您需要完成一些额外的工作。 本教程可能会对您有所帮助。
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.
另一个问题确实会通过给你一些代码来帮助你。但您可能需要一个解释。
您无法分配尺寸,因为它没有任何意义 - 一旦加载图像数据,更改尺寸将需要重新排列数据,插入或删除像素数据部分。简单的尺寸分配没有足够的信息来为您正确完成此操作。
更改图像大小的正确方法是创建一个新图像,然后将旧图像绘制到其上。为此,请参阅已引用的其他问题。
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.