I need to cut the UIImage by the example of the picture that is. Somehow this can be done via SKSpriteNode but the guides read did not give me an answer.

enter image description here

  • Do you need to cut the image by mask? Why is this asterisk in question? - Max Mikheyenko
  • @MaxMikheyenko for this star I need to crop the picture. It serves as a mask. And there are about a dozen different ... - Svyatoslav Boyko

1 answer 1

Here is a tutorial found on this topic.

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); return [UIImage imageWithCGImage:masked]; }