位图数据绘制方法-用蓝色替换不存在的像素

发布于 2024-09-06 17:17:15 字数 559 浏览 0 评论 0原文

我有一个凸多边形(不是矩形)形状的精灵。
如果我使用

var bmd:BitmapData = new BitmapData(width,height);  
bmd.draw(someSprite,someMatrix,null,null,null);

以下方式拍摄快照:我会得到如下图像:

点击此处查看图片

在这张图片中,我自己添加了绿色边界,只是为了显示
图像的尺寸。

所以,当我拍摄凸多边形精灵的快照时
使用 BitmapData 类的绘制方法,我得到了一个红色三角形
内部有一个白色椭圆,对于其余区域,我得到了 while 像素。

我想用蓝色像素替换那些外部白色像素。

我该怎么做?

I have a Sprite which is in the shape of a Convex polygon(not rectangular).
If I take its snapshot using :

var bmd:BitmapData = new BitmapData(width,height);  
bmd.draw(someSprite,someMatrix,null,null,null);

I get an image like this :

Click here to see the image

In this image, I have added the green boundary myself, just to show
the dimensions of the image.

So, when I took a snapshot of the convex polygon shaped sprite
using draw method of the BitmapData class, I got a red triangle
with a white ellipse inside and for rest of the area, I got while pixels.

I want to replace those outer white pixels with blue colored pixels.

How do I do it?

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

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

发布评论

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

评论(1

彼岸花似海 2024-09-13 17:17:15

您可以使用 BitmapData.floodFill() 方法。
它的工作原理就像“油漆桶工具”。

剩下的就是在要替换的白色区域内找到一个像素。
例如,如果您确定精灵周围始终存在白色边框,则可以假设左上角像素是完美点。这样做就可以解决问题:

bmd.floodFill(0, 0, 0xff0000ff); //note that the color is in ARGB format.

如果你不能假设这一点,那么问题不在于填充白色区域,而在于找到它。那么我们需要更多地了解您的问题。
例如,我们不能只是循环遍历边界寻找白色像素,因为这些像素实际上可能是中间的椭圆。

You could use the BitmapData.floodFill() method.
It works just like the "paint bucket tool".

All that is left is finding a pixel inside the white area you want to replace.
For instance, if you are certain that there will always exist a white border around the sprite, you can assume the top-left pixel is a perfect spot. Doing so would then solve the problem:

bmd.floodFill(0, 0, 0xff0000ff); //note that the color is in ARGB format.

If you can't assume that, the problem is not about filling the white area, but finding it. We'd need to know more about your problem then.
We couldn't just loop through the borders looking for white pixels as those could be actually the middle ellipse, for example.

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