I am creating an app which lets the user select a image from the photo library using UIImagePickerController and then saves the image using ALAssets Library. But there is a difference between the quality and size of the image being saved by my app. compared to the original image which was picked from the photo library.
I added logging to check the size of the image being picked and the image saved in photo library using ALAsset library.
-(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];
}];
}
}
The size in bytes of the images when picked and passed to be saved is equal and approximately 4 MB. But the size of the image saved in the photo library is only a little more than 2 MB. Please let me know why is there a difference in the image? And what can I do to save the image with exact size as of the original image?