Loi Truong
Loi Truong

Reputation: 31

How to detect transparent area in image?

i research about merge many image into a image in 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. So if i detected all transparent area in this image, i will have a CGRect Array.

You can see my image:

nhay.net/CES.jpg

Please help me, thank you very much!!

Upvotes: 3

Views: 1518

Answers (1)

Rob
Rob

Reputation: 438467

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.

But to extrapolate from that to the programmatic building an array of CGRect corresponding to contiguous transparent pixels is non-trivial. If you make simplifying assumptions about the nature of the transparent regions (e.g. 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.

Upvotes: 1

Related Questions