I'm using writeImageToSavedPhotosAlbum:metadata:completionBlock: to save images to the camera roll (GPS data is in dictionary passed to metadata). However pictures are misoriented (as I flip the device while taking the pictures).
There's another function writeImageToSavedPhotosAlbum:orientation:completionBlock: but I won't be able to pass EXIF data.
According to the documentation, there's kCGImagePropertyOrientation property to set orientation manually but I'm having problems with detecting current orientation of the device while taking the picture and saving it.
Has anyone achieved saving picture with EXIF data and proper orientation? Any help would be very appreciated.
Here's my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
[imageView setImage:image];
if(sourceCamera) {
//EXIF and GPS metadata dictionary
(...)
//saving image
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeImageToSavedPhotosAlbum:[image CGImage]
metadata:dict
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error == nil) {
NSLog(@"saved");
} else {
NSLog(@"error");
}
}];
[al release];
}
}
Best wishes,
a.
Here's how to get to the new information pane in the Photos app on iPhones and iPads running iOS 15/iPadOS 15. Open the Photos app and tap an image in your Library. Tap the info button (the encircled "i" icon) below the image. Look for the EXIF data in the box below the date and time.
Add, edit, and remove other metadata 1) Open the image in the Exif Metadata app. 2) Tap Edit from the top right or scroll to the bottom and tap Edit Exif. 3) From here, tap the individual fields to add new values or edit the current ones. Finally, tap Save.
You can either use Exif Metadata or Photo & Video Metadata Remover to view the Exif data of any photo on your iPhone or iPad. You'll also be able to use these apps to remove the metadata. To view the Exif data of an image, open the Exif Metadata app and it'll ask your permission to access your photos.
You need to map the UIImageOrientation values to the corresponding EXIF orientation values when setting kCGImagePropertyOrientation
. That mapping is:
UIImageOrientationUp: 1
UIImageOrientationDown: 3
UIImageOrientationLeft: 8
UIImageOrientationRight: 6
UIImageOrientationUpMirrored: 2
UIImageOrientationDownMirrored: 4
UIImageOrientationLeftMirrored: 5
UIImageOrientationRightMirrored: 7
Note that UIImageOrientationLeft and UIImageOrientationRight are the opposite of what you might expect from the documentation; the little sample images are what you get if you apply the orientation to an upright image, rather than the orientation of the raw image data that will give an upright image when the orientation is applied.
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