Created
April 22, 2015 03:16
-
-
Save zhigang1992/b4cccd77557dab74e3aa to your computer and use it in GitHub Desktop.
Rubymotion Versions Of Image_Cropper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIImage | |
def crop_at(rect) | |
UIGraphicsBeginImageContext(rect.size) | |
context = UIGraphicsGetCurrentContext() | |
clipped_rect = CGRectMake(0, 0, rect.size.width, rect.size.height) | |
CGContextClipToRect( context, clipped_rect) | |
draw_rect = CGRectMake(rect.origin.x * -1, | |
rect.origin.y * -1, | |
self.size.width, | |
self.size.height) | |
CGContextTranslateCTM(context, 0.0, rect.size.height) | |
CGContextScaleCTM(context, 1.0, -1.0) | |
CGContextDrawImage(context, draw_rect, self.CGImage) | |
cropped = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
cropped | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment