Fatsest way to edit alpha CGImage (or UIImage) by touch and then display?

I have two kinds of images, one on top of the other, with two different images. When the user touches the image and moves his finger, the top image should become transparent along the touch points with a fixed radius. (As a PhotoChop application).

I am currently doing it like this ...

  • For every touch.
  • Get a copy of the image buffer from the CGImage of the top image.
  • Edit the alpha channel of the buffer to create a transparent circle centered at the touch point.
  • Create a new CGImage from the buffer.
  • Create a UIImage from CGImage and use the new UIImage as the image of the top image.

This works, but since you can see too many copies, it is created and used, and it is slow.

Can someone please suggest me a faster way to do the same?

+3
source share
1 answer
CGImageCreateWithMask

As the user draws, change CGBitmapContextwith the changes. Keep bound CGImage, which refers to the context. Create a masked image from the original and mask and create from it UIImage.

CGImage, and therefore CGBitmapContextshould be gray. You can use CGImageMaskCreateor CGImageCreateto make the image, but the first is preferable.

, , , UIImage, CGBitmapContext. , , - , , , setNeedsDisplay , UIImage.

+1

Source: https://habr.com/ru/post/1744662/


All Articles