Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. /**
  2. * アスペクト比を保ってUIImageをリサイズ
  3. *
  4. */
  5. + (UIImage *)resizeAspectFitWithSize:(UIImage *)srcImg size:(CGSize)size
  6. {
  7. CGFloat widthRatio = size.width / srcImg.size.width;
  8. CGFloat heightRatio = size.height / srcImg.size.height;
  9. CGFloat ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio;
  10.  
  11. CGSize resizedSize = CGSizeMake(srcImg.size.width*ratio, srcImg.size.height*ratio);
  12.  
  13. UIGraphicsBeginImageContext(resizedSize);
  14. [srcImg drawInRect:CGRectMake(0, 0, resizedSize.width, resizedSize.height)];
  15. UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
  16.  
  17. UIGraphicsEndImageContext();
  18.  
  19. return resizedImage;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement