Search code examples
iphoneuiimagearea

Iphone, calculating area within an image


Starting a new app and before i get to it would like to know your thoughts... What's the best way to go about calculating image areas.... lets say i have a square 100 X 100 pixels and it has another square on top of it (10 by 10). how would i go about finding the area showing of the 100x100 square? what if there's multiple 10x10 squares and they overlap?

Thanks!


Solution

  • Start with a 10,000-element bitmap of all zeros, paint all the squares as ones, and count the zero bits when you're done.

    The math will be much faster if you use a 128x128 square, which can be represented by 128 pairs of 64-bit unsigned integers on a 64-bit architecture, or groups of four 32-bit unsigned integers on a 32-bit chip.