圖片的裁剪與壓縮 阿新 • • 發佈:2019-02-01 壓縮圖片,是減少的畫素點,從而使相片大小變小,裁剪圖片的改變的照片的尺寸,相片的大小一般變化不大(在這個方法裡面) //壓縮圖片質量 -(UIImage *)originalImage:(UIImage *)image scal:(float)scal { NSData *imageData = UIImageJPEGRepresentation(image, scal); UIImage *newImage = [UIImage imageWithData:imageData]; return newImage; } //壓縮圖片尺寸 -(UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize { // Create a graphics image context UIGraphicsBeginImageContext(newSize); // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage; }