Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom image mask in iOS

I have a issue with masking images. I do game "puzzle" and have to make custom images. I found and tried 2 way of custom cropping:

  1. Using CALayer.mask property.
  2. Using UIImage.mask property.

In first option i create my custom path, then assign it to CAShapeLayer.path property, then assign CAShapeLayer to CALayer.mask property. At the end i have custom cropped image. In second option i use firstly use CGImageMaskCreate() method (i use previously created black mask images of puzzle), then CGContextClipToMask(). In either options i have problem with performance (mostly when i crop image into 16 puzzles and drag in over the screen).

Is there any other approaches to crop image in custom way. (I don't know how to solve performance problem). Thanks in advance.

like image 897
akozin Avatar asked May 04 '11 08:05

akozin


1 Answers

There are lots of UIImage-categories out there you can use for this. Give me a moment and I'll post some links here:

  • Cropping an UIImage (not really a category though, but it'll fit)
  • UIImage: Resize, then Crop
  • https://sites.google.com/a/injoit.com/knowledge-base/for-developers/graphics/uiimage-routines-scaling-cropping-rotating-etc
  • http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
  • http://maybelost.com/2010/11/cropping-a-uiimage-on-iphone/
like image 121
cutsoy Avatar answered Sep 25 '22 22:09

cutsoy