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;
新聞熱點
疑難解答