比较两个对位图相互匹配AS3 [英] Comparing two bitmaps against each other for match as3

查看:137
本文介绍了比较两个对位图相互匹配AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对基于化妆的小图像的另一图像的顶部位置的图像。较小的图像切出一个较大的图像,我需要它被定位完全放大图像上,使它看起来像一个单一的形象,但允许单独的过滤器和阿尔法被应用。由于图像不是简单的矩形或圆形,而是复杂的卫星图像,我不能简单地重绘他们在code。我有好几个图像,因此不喜欢手动查找每个图像中的每个位置,硬的动作进行手动设置。有什么办法让我品尝危害较大的图像小5-10平方像素的面积和设置x和更小的图像的y值,如果是绝配被发现?所有的图像都在数组中,并通过他们的迭代已经设置,我只是需要一种方法来品尝并匹配像素。我的第一个猜测是循环的图像逐像素向右和向下,覆盖整个位图,并移动到下一个孩子一次比赛在数组中被发现,离开匹配的子女,这是完美的比赛时被发现。

I'm trying to position an image on top of another image based upon the make-up of the smaller image. The smaller image is a cut-out of a larger image and I need it to be positioned exactly on the larger image to make it look like a single image, but allow for separate filters and alphas to be applied. As the images are not simple rectangles or circles, but complex satellite images, I cannot simply redraw them in code. I have quite a few images and therefore do not feel like manually finding the position of each image every and hard setting them manually in actionscript. Is there any way for me to sample a small 5-10 sq. pixel area against the larger image and set the x and y values of the smaller image if a perfect match is found? All the images are in an array and iterating through them has already been set, I just need a way to sample and match pixels. My first guess was to loop the images pixel by pixel right and down, covering the whole bitmap and moving to the next child in the array once a match was found, leaving the matched child where it was when the perfect match was found.

推荐答案

我希望我正确地理解你的问题。

I hope I understood your question correctly.

有可能是使用copypixels来实现你想要的选项。您可以使用bitmapdata.rect价值利用泰德矩形和一个传动点的大位图来确定你想要的样本的大小,以及循环。让我们来看看,如果我能$ C C此$了...

There may be an option that uses copypixels to achieve what you want. You can use the bitmapdata.rect value to determine the size of the sample you want, and loop through the bigger bitmap using thet rectangle and a moving point. Let's see if I can code this out...

function findBitmapInBitmap(tinyimg:BitmapData, largeimg:BitmapData):Point {
    var rect:Rectangle = tinyimg.rect;
    var xbound:uint = largeimg.rect.width;
    var ybound:uint = largeimg.rect.height;
    var imgtest:BitmapData = new BitmapData(tinyimg.rect.width, tinyimg.rect.height);

    for (var ypos:uint = 0, y <= ybound, y++) {
        for (var xpos:uint = 0, x <= xbound, x++) {
            imgtest.copyPixels(largeimg, rect, new Point(xpos, ypos);
            if (imgtest.compare(tinyimg) == 0) return new Point(xpos, ypos);
        }
    }

    return new Point(-1,-1); // Dummy value, indicating no match.

}

类似的规定应该努力 - 我敢肯定有空间code优雅和可能的优化。但是,好像是这样的方法将是非常缓慢的,因为你必须检查每个像素进行匹配。

Something along those lines should work - I'm sure there's room for code elegance and possible optimization. However, it seems like something like this method would be very slow, since you'd have to check each pixel for a match.

有一个更好的办法。拆分你的大图像分成层,并使用位图传输技术,复合它们在运行时。你的情况,你可以创建一个地面纹理没有卫星,然后分别建立卫星,并使用copyPixels方法。无论您​​想放置。谷歌的Blitting在AS3找到一些很好的教程。我目前正在使用这种技术的游戏项目,这是一个很好的方法。

There is a better way. Split your big image into layers, and use the blitting technique to composite them at runtime. In your case, you could create a ground texture without satellites, and then create the satellites separately, and use the copyPixels method to place them whereever you want. Google "blitting in as3" to find some good tutorials. I'm currently working on a game project that uses this technique and it's a very good method.

祝你好运!

编辑:忘了code在默认return语句。使用这种方法,你就必须返回一个无效的点(如(-1,-1)),并检查它的功能外。或者,你可以只是你的小位图复制到函数中最大的一个,这将是更符合逻辑,但我不知道你的要求。

Forgot to code in a default return statement. Using this method, you'd have to return an invalid point (like (-1,-1)) and check for it outside the function. Alternatively, you could just copy your small bitmap to the big one within the function, which would be much more logical, but I don't know your requirements.

这篇关于比较两个对位图相互匹配AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆