时间:2019-03-17 标签:c#winformsGDI+
我有一个通过多次平铺同一图形创建的位图。创建位图后,它会根据特定标准为图块着色。
加载位图后,我想为用户提供根据进一步预定义的标准更改图块颜色的选项。因此,我是否需要丢弃当前位图,使用新颜色再次生成并附加到面板。或者我可以迭代每个图块的位图并以这种方式更改颜色吗?
谢谢。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于用户更改图块颜色的频率。如果他们不会经常这样做,那么生成新的位图可能会更容易(主要是因为您的代码似乎针对这种情况进行了优化)。
然而,更好的性能可能是使用 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.
据我所知,浏览位图并更改颜色的唯一方法是逐个像素地进行操作,因此我认为最好的方法是当用户选择新颜色时从头开始生成位图。
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.