0

Let's say I have a solid, irregularly shaped (but enclosed) shape on screen in iOS (one colour). I then want to "erase" portions of that shape by dragging my finger around like you would in a typical kids colouring app, erasing with a fixed brush size where I touch the screen.

I could easily accomplish all this with something like an image mask and touch detection however, as a requirement, I also need to determine the rough percentage of the shape that remains.

For example I need to know when 50% of the random enclosed shape has been "erased".

What's the best way of approaching this problem? Are there any existing iOS compatible libraries that can handle it? I'm thinking that I would need to keep track of a ton of polygons and calculate all the overlaps but it seems like there must be a solution to this problem.

EDIT: I have done research into this problem however tracking all the polygons manually and calculating all their positions and area overlaps seems overly complicated. I was simply wondering if anyone else has run into a similar issue and found a better solution.

iamamused
  • 2,720
  • 3
  • 25
  • 17

1 Answers1

2

you will need to first know the fixed space of the image view. then you will need to know the percentage of blank space when the new image is loaded. pixel

double percentageFilledIn = ((double)nonBlankPixelCount/totalpixels);

After you get that value you will need to use that percentage as your baseline for the existing percentage

your new calculation will look like this.

double percentageOfImageLeft = ((double)nonBlankPixelCount/totalpixels/percentageFilledIn);

this calculation will likely be processor intensive. I would only calculate sparingly.

Since this post is not about code and more about login I will let you determine your logic for detecting non blank pixels.

here is how to find a pixel color.

How to get Coordinates and PixelColor of TouchPoint in iOS/ObjectiveC

Good luck.

Community
  • 1
  • 1
The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69