标签:
1、生成指定宽高的UIImage对象(oldImage为原始图片对象,newImage为操作后的图片对象)
// 参数1:图片的尺寸 参数2:是否透明(没看出YES和NO有什么区别) 参数3:缩放(1表示不缩放)
(1) UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)
(2) UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight));
// 用(1)和(2)都可以
[oldImage drawInRect:CGRectMake(0, 0, 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;
标签:
原文地址:http://www.cnblogs.com/chenyanliang/p/first-.html