Skip to content

Instantly share code, notes, and snippets.

@zhigang1992
Created April 22, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhigang1992/b4cccd77557dab74e3aa to your computer and use it in GitHub Desktop.
Save zhigang1992/b4cccd77557dab74e3aa to your computer and use it in GitHub Desktop.
Rubymotion Versions Of Image_Cropper
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