一般用imagePickerController获取到dic以后常用的方法是使用
UIImage *image = [dic objectForKey:@"UIImagePickerControllerOriginalImage"];
来获取原图,但是我使用这个方法获取到得图片并不是原图,而是尺寸经过压缩后的,后来找到了一个新的方法来进行获取 直接贴代码
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library assetForURL:[dic objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) { ALAssetRepresentation *representation = [asset defaultRepresentation]; CGImageRef imgRef = [representation fullResolutionImage]; UIImage *image = [UIImage imageWithCGImage:imgRef scale:representation.scale orientation:(UIImageOrientation)representation.orientation]; NSData * data = UIImageJPEGRepresentation(image, 0.5); }failureBlock:^(NSError *error){ NSLog(@"couldn‘t get asset: %@", error); } ];
不使用UIImagePickerControllerOriginalImage获取原图
时间: 2024-10-08 18:50:13