0

For the project I am working on I have an image. For testing purposes I am just using a red square that is 100 pixels by 100 pixels.

What I want to do is to be able to define parts of the image to not render. For example, let's say I want to erase a circle in the middle of the red square. If that is done, we should see the red square, minus the erased circle and whatever is behind that square ( where the circle was erased ).

I am not sure how I would do this besides storing each pixel in a 2D array and processing it that way. The images are going to be much larger than 100 pixels in the final implementation though so this seems inefficient and would cost considerable amounts of memory.

If anyone has any alternative solutions ( or ways to improve the one I was thinking of/examples of this being efficient for images that are 10000 by 10000 pixels for example ), it would be greatly appreciated.

CMilby
  • 624
  • 1
  • 6
  • 23

1 Answers1

1

Look into using masking, with a “Destination Out” blend mode. Using this, you can draw a mask over the image using UIBezierPaths, then “cut them out”. I did something very similar a while back trying to cut out a circle from a UIView to act as a tooltip ring around an item.

Mask a UIView with a cut-out circle

https://www.belightsoft.com/products/arttext/ATHelp/layers_blending.html#destination_out

Community
  • 1
  • 1
Luke
  • 9,512
  • 15
  • 82
  • 146