时间:2019-03-17 标签:c#winformsGDI+

发布于 2024-10-11 20:43:08 字数 159 浏览 1 评论 0原文

我有一个通过多次平铺同一图形创建的位图。创建位图后,它会根据特定标准为图块着色。

加载位图后,我想为用户提供根据进一步预定义的标准更改图块颜色的选项。因此,我是否需要丢弃当前位图,使用新颜色再次生成并附加到面板。或者我可以迭代每个图块的位图并以这种方式更改颜色吗?

谢谢。

I have a bitmap that I have created by tiling the same graphic multiple times. When the bitmap is created it colours the tiles based on specific criteria.

When the bitmap is loaded, I then want to give the user the options to change the tile colours based on further pre-defined criteria. Would I therefore need to discard the current bitmap, generate again with the new colours and attach to the panel. Or can I iterate through the bitmap for each tile and change the colours that way?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

终遇你 2024-10-18 20:43:08

这取决于用户更改图块颜色的频率。如果他们不会经常这样做,那么生成新的位图可能会更容易(主要是因为您的代码似乎针对这种情况进行了优化)。

然而,更好的性能可能是使用 Bitmap.LockBits/UnlockBits 方法获取位图中的像素数据,然后直接操作像素数据。有关如何执行此操作的示例,请参阅有关 Bitmap.LockBits 方法的 MSDN 文档 (http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx)。

It depends on how often the user is likely to change the tile colours. If they're not going to be doing it too often then it's probably easier to generate a new bitmap (mostly because your code seems like it's optimized for this scenario).

A better more performant possibiliy however is to use the Bitmap.LockBits/UnlockBits methods to get at the pixel data in the bitmap then manipulate the pixel data direcly. See the MSDN documentation on the Bitmap.LockBits method (http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx) for a sample on how to do this.

你怎么敢 2024-10-18 20:43:08

据我所知,浏览位图并更改颜色的唯一方法是逐个像素地进行操作,因此我认为最好的方法是当用户选择新颜色时从头开始生成位图。

As far as I know, the only way you can go through the bitmap and change colors is to do it pixel by pixel, so I think your best shot is to generate the bitmap from scratch when the user selects new colors.

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