Created by Jamz Tang at 10 September 2011
You probably aware of the method
that's already defined in the Foundation framework. It is absolute fine for developers familiar well with CoreGraphics and doesn’t mind manually taking care of the image orientations.
We loved UIKit anyway.
Now you use this instead of the CoreGraphics method.
+ (UIImage *)imageWithImage:(UIImage *)image cropInRect:(CGRect)rect;
Last but not least, you’d somehow want to further abstract it with a proportional rect value. (Imagine you are defining a cropping area on the screen and want to crop a full sized image, you’d transform the visible area to the full sized photo). A handly method is also created for this purpose.
+ (UIImage *)imageWithImage:(UIImage *)image cropInRelativeRect:(CGRect)rect;
Enjoy the snippet!
Clone this repository:
git clone git://gist.github.com/6912933.git UIImage-JTImageCrop
If you think this is useful, share this article with your friends :)blog comments powered by Disqus