ユーザーが UIImagePickerController を使用して写真ライブラリから画像を選択し、ALAssets ライブラリを使用して画像を保存できるアプリを作成しています。しかし、私のアプリで保存されている画像の品質とサイズには違いがあります。写真ライブラリーから選んだ元の画像と比較してください。
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 です。しかし、フォト ライブラリに保存される画像のサイズは 2 MB 強にすぎません。画像に違いがある理由を教えてください。また、元の画像と同じサイズで画像を保存するにはどうすればよいですか?