1、生成指定宽高的UIImage对象(oldImage为原始图片对象,newImage为操作后的图片对象)

// 参数1:图片的尺寸  参数2:是否透明(没看出YES和NO有什么区别)  参数3:缩放(1表示不缩放)
() UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)
() UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight));
// 用(1)和(2)都可以
[oldImage drawInRect:CGRectMake(, , newWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;

2、对UIImage进行裁剪

// bounds(NSRect) : 其中x,y 为截取的起始点,width,height 为截取图片尺寸
CGImageRef imageRef = CGImageCreateWithImageInRect([oldImage CGImage], bounds);
UIImage *newImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return newImage;
05-11 15:26