Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. -(UIImage*)scaleToSize:(CGSize)size image:(UIImage*)image
  2. {
  3. UIGraphicsBeginImageContext(size);
  4.  
  5. // Draw the scaled image in the current context
  6. [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
  7.  
  8. // Create a new image from current context
  9. UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  10.  
  11. // Pop the current context from the stack
  12. UIGraphicsEndImageContext();
  13.  
  14. // Return our new scaled image
  15. return scaledImage;
  16. }
  17.  
  18. -(UIImage *)cropCanvas:(UImage *)input x1:(int)x1 y1:(int)y1 x2:(int)x2 y2:(int)y2{
  19. CGRect rect = CGRectMake(x1, y1, input.size.width-x2-x1, input.size.height-y2-y1);
  20. CGImageRef imageref = CGImageCreateWithImageInRect([input CGImage], rect);
  21. UIImage *img = [UIImage imageWithCGImage:imageref];
  22. return img;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement