0
我創建的應用程序可讓用戶使用UIImagePickerController從照片庫中選擇圖像,然後使用ALAssets庫保存圖像。 但是,我的應用程序保存的圖像的質量和尺寸存在差異。與從照片庫中選取的原始圖像相比較。ALAsset庫在將圖像保存在照片庫中時縮小圖像的大小
我添加了日誌記錄功能,以檢查所選圖像的大小以及使用ALAsset庫保存在照片庫中的圖像。
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"Size of the image picked in bytes: %i",[UIImageJPEGRepresentation(image,1.0f) length]);
}
-(void)methodToSaveImage:(UIImage*)image metadata:(NSMutableDictionary*)info
{
@autoreleasepool {
NSLog(@"Size of image passed to be saved: %i",[UIImageJPEGRepresentation(image,1.0f) length]);
[self writeImageToSavedPhotosAlbum:image.CGImage metadata:info
completionBlock:^(NSURL* assetURL, NSError* error) {
//error handling
if (error!=nil) {
return;
}
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
NSLog(@"Size of image after being saved in photo library : %i",[myasset defaultRepresentation].size);
};
//
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"cant get image - %@",[myerror localizedDescription]);
};
[self assetForURL:assetURL
resultBlock:resultblock
failureBlock:failureblock];
}];
}
}
選取並傳遞要保存的圖像的字節大小相等且大約爲4 MB。但保存在照片庫中的圖像的大小隻有2MB多一點。請讓我知道爲什麼圖像有差異?我能做些什麼來保存與原始圖像一樣大小的圖像?
它會幫助http://stackoverflow.com/questions/12355589/uiimagepickercontrolleroriginalimage-vs-original-asset-data –