I have an ipad app which takes images from Photos application using ALAssetsLibrary
and then uploads them to web server. So far everything is working fine.
Now if i go to the photos application and edit an image (say crop) and upload, the original un-cropped is getting uploaded. I am accessing/saving a the photo using the asset url.
Ex:
createPhoto:
assetUrl: assets-library://asset/asset.JPG?id=542F09CA-00E1-412E-A7E6-0C222E3F8FFB&ext=JPG,
UTIs: (
"public.jpeg"
),
UTI:public.jpeg
This is not a ALAssetsLibrary
cache issue becuase, i have tried editing, kill app, start, upload which still uploads old image.
Question:
I recognized the same behaviour and did some testing a while ago. Let me share my results with you:
The edited image you only get through the fullScreenImage method. This is also mentioned in Apple's documentation: "In iOS 5 and later, this method returns a fully cropped, rotated, and adjusted image—exactly as a user would see in Photos or in the image picker."
The fullResolutionImage and getBytes method return the unedited image. However, the editing parameters like crop are saved in the image metadata. This metadata info however is only interpreted by Apple apps like Aperture and iPhoto.
You can find out, if an image had been edited, by inspecting he image metadata. Compare the metadata of an unedited and edited image and look for differences in the metadata fields.
-(UIImage*)fullScreenImage:(ALAsset *)imageAsset{
ALAssetRepresentation *assetRepresentation = [imageAsset defaultRepresentation];
CGImageRef fullResImage = [assetRepresentation fullResolutionImage];
NSString *adjustment = [[assetRepresentation metadata] objectForKey:@"AdjustmentXMP"];
if (adjustment) {
NSData *xmpData = [adjustment dataUsingEncoding:NSUTF8StringEncoding];
CIImage *image = [CIImage imageWithCGImage:fullResImage];
NSError *error = nil;
NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData
inputImageExtent:image.extent
error:&error];
CIContext *context = [CIContext contextWithOptions:nil];
if (filterArray && !error) {
for (CIFilter *filter in filterArray) {
[filter setValue:image forKey:kCIInputImageKey];
image = [filter outputImage];
}
fullResImage = [context createCGImage:image fromRect:[image extent]];
}
}
UIImage *result = [UIImage imageWithCGImage:fullResImage
scale:[assetRepresentation scale]
orientation:(UIImageOrientation)[assetRepresentation orientation]];
return result;
}
In above function pass ALAsset value then you the edited image ...:)
Above code for getting edited image from Meta data
If u go with full screen image then also u will get the edited image
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef iref = [representation fullScreenImage];
UIImage *editedImage = [UIImage imageWithCGImage:iref];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With