简体   繁体   English

如何检测图像中的透明区域?

[英]How to detect transparent area in image?

i research about merge many image into a image in iphone. 我研究将许多图像合并到iphone中的图像中。 But i have some problem about that. 但我有一些问题。 I want to detect transparent areas, which has a white background. 我想检测具有白色背景的透明区域。 I think it's possible to get a CGRect rectangle around the area during this and after i will drag my image into transparent area, but I do not know how I can identify it. 我认为在此期间可以在该区域周围获得一个CGRect矩形,之后我将我的图像拖动到透明区域,但我不知道如何识别它。 So if i detected all transparent area in this image, i will have a CGRect Array. 因此,如果我在此图像中检测到所有透明区域,我将拥有一个CGRect数组。

You can see my image: 你可以看到我的形象:

nhay.net/CES.jpg

Please help me, thank you very much!! 请帮帮我,非常感谢!!

In terms of detecting transparent pixels, you can access the pixel buffer as described in Technical Q&A QA1509 and then iterate through the pixel buffer looking for pixels with an alpha channel value of less than 1.0. 在检测透明像素方面,您可以按照技术问答QA1509中的描述访问像素缓冲区,然后遍历像素缓冲区,查找alpha通道值小于1.0的像素。

But to extrapolate from that to the programmatic building an array of CGRect corresponding to contiguous transparent pixels is non-trivial. 但是,从那个到程序化建筑的CGRect对应于连续透明像素的CGRect数组是非平凡的。 If you make simplifying assumptions about the nature of the transparent regions (eg circular), it's quite a tractable little problem, though your thin rounded rectangle that intersects many of the circles complicates the problem. 如果你简化了关于透明区域(例如圆形)的性质的假设,那么这是一个相当容易处理的小问题,尽管与许多圆相交的薄圆角矩形使问题复杂化。

If your image with transparent areas is predefined, though, I'd probably just define them manually rather than determining it programmatically. 但是,如果预定义了具有透明区域的图像,我可能只是手动定义它们而不是以编程方式确定它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM