如何设置 Bitmap.Width 和 Bitmap.height

发布于 2024-11-07 10:56:30 字数 234 浏览 0 评论 0原文

您好,我已经加载了一个位图,我需要设置自己的高度和宽度,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入怼 2024-11-14 10:56:30

这些参数是只读的,因为位图是固定大小的。更改位图结构的大小不会对图像产生任何影响。您需要的是缩放图像,而不仅仅是分配宽度/高度属性。

据我所知,没有内置方法可以为您执行此操作,因此您需要完成一些额外的工作。 教程可能会对您有所帮助。

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.

ま柒月 2024-11-14 10:56:30

另一个问题确实会通过给你一些代码来帮助你。但您可能需要一个解释。

您无法分配尺寸,因为它没有任何意义 - 一旦加载图像数据,更改尺寸将需要重新排列数据,插入或删除像素数据部分。简单的尺寸分配没有足够的信息来为您正确完成此操作。

更改图像大小的正确方法是创建一个新图像,然后将旧图像绘制到其上。为此,请参阅已引用的其他问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文