位图数据绘制方法-用蓝色替换不存在的像素
我有一个凸多边形(不是矩形)形状的精灵。
如果我使用
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 :
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
BitmapData.floodFill()
方法。它的工作原理就像“油漆桶工具”。
剩下的就是在要替换的白色区域内找到一个像素。
例如,如果您确定精灵周围始终存在白色边框,则可以假设左上角像素是完美点。这样做就可以解决问题:
如果你不能假设这一点,那么问题不在于填充白色区域,而在于找到它。那么我们需要更多地了解您的问题。
例如,我们不能只是循环遍历边界寻找白色像素,因为这些像素实际上可能是中间的椭圆。
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:
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.