1,图片尺寸压缩
-(UIImage *) imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth//图片压缩,第二个参数为最终宽度
{
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = defineWidth;
CGFloat targetHeight = (targetWidth / width) * height;
UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));
[sourceImage drawInRect:CGRectMake(0,0,targetWidth, targetHeight)];
UIImage* newImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
方法举例:
UIImage *newImage=[selfimageCompressForWidth:imagetargetWidth:image.size.width/2];
NSData *data = UIImagePNGRepresentation(image);//未压缩
NSData *data =UIImageJPEGRepresentation(image,0.5);//压缩
3,QBImagePickerController多选照片出现的问题
QBImagePickerController.m中方法
- (NSDictionary *)mediaInfoFromAsset:(ALAsset *)asset
[mediaInfo setObject:[UIImageimageWithCGImage:[[assetdefaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"];
3.2,取照片后为照片原图:
[mediaInfo setObject:[UIImageimageWithCGImage:[[assetdefaultRepresentation] fullResolutionImage]] forKey:@"UIImagePickerControllerOriginalImage"];
3.3,3.2中照片较大会出现左转90度,解决方法为:
[mediaInfo setObject:[UIImageimageWithCGImage:[[assetdefaultRepresentation] fullResolutionImage]
scale:[assetdefaultRepresentation].scale
orientation:(UIImageOrientation)[assetdefaultRepresentation].orientation]forKey:@"UIImagePickerControllerOriginalImage"];
3中以上三点为并列语句。