Actionscript 3:getColorBoundsRect

发布于 2024-11-16 02:54:41 字数 581 浏览 11 评论 0原文

我有一个问题。我有一个带有 2 个红色圆圈的 BitmapData。我想找到矩形区域或每个圆。如果我使用 [B]getColorBoundsRect[/B] 我会得到 2 个圆圈包围的最小区域。

我怎样才能做到这一点并获得圆圈的单独面积? 下面是我为了更好地解释我的问题而创建的图表:
http://img831.imageshack.us/img831/3360/sampleja.png

以前有人问过这个问题,但不太明白 所提供的解决方案如何解决问题。 http://www.kirupa.com/forum/showthread。 php?324586-Question-to-getColorBoundsRect

希望这里有人能给我一些启发。谢谢一百万。

I have a question. I have a BitmapData with 2 red circles. I want to find the rectangle area or each circle. If i use [B]getColorBoundsRect[/B] I get the smallest area enclosed by the 2 circles.

How can i go about this and get individual area of the circles?
below is a diagram i created to better explain my question:
http://img831.imageshack.us/img831/3360/sampleja.png

previously this question was asked before but don't quite understand
how the provided solution solved the problem.
http://www.kirupa.com/forum/showthread.php?324586-Question-to-getColorBoundsRect

hope someone here can shed some light for me. Thanks a million.

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

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

发布评论

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

评论(1

〃安静 2024-11-23 02:54:41

有一个非常巧妙的技巧可以做到这一点。首先,您需要确保位图数据中仅获得两种颜色(阈值即可解决问题)。之后,您可以将 getColorBounds 与 floodFill 查找图像中的所有斑点。伪代码将是这样的:

//Do the following until rect.width is zero.
rect = bmp.getColorBoundsRect(red);
//check the first row of pixels until you find the start of the blob
for(y = rect.y; y < rect.height + rect.y; y++) {
  if(bmp.getPixel(rect.x,y) == red) {
    bmp.floodFill(rect.x,y, green); // paint the blob green
    blobs.push(bmp.getColorBoundsRect(green)); // get the green bounds and push a new blob
    bmp.floodFill(rect.x,y, white); // clear it
    break;
  }
}

There's a very neat trick to do it. First you need to make sure you get only two colors in your BitmapData (threshold will do the trick). After that, you can use getColorBounds together with floodFill to find all blobs in the image. The pseudo-code would be something like this:

//Do the following until rect.width is zero.
rect = bmp.getColorBoundsRect(red);
//check the first row of pixels until you find the start of the blob
for(y = rect.y; y < rect.height + rect.y; y++) {
  if(bmp.getPixel(rect.x,y) == red) {
    bmp.floodFill(rect.x,y, green); // paint the blob green
    blobs.push(bmp.getColorBoundsRect(green)); // get the green bounds and push a new blob
    bmp.floodFill(rect.x,y, white); // clear it
    break;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文