UIImage 操作
2016-01-08 本文已影响48人
秀才不才
ps:东西太多了
缩放
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size {
UIImage *newImg;
UIGraphicsBeginImageContext(size);
CGRect imageRect = CGRectMake(0, 0, size.width, size.height);
[image drawInRect:imageRect];
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImg;
}
截取
- (UIImage *)captureImage:(UIImage *)image toSize:(CGRect)rect {
CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, rect);
UIImage *captureImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return captureImage;
}