Want more features on Pastebin? Sign Up, it's FREE!
Guest

UIImagePickerController and extracting EXIF data from existing photos

By: a guest on Jan 8th, 2012  |  syntax: None  |  size: 3.31 KB  |  views: 1,058  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #import "EXFJpeg.h"
  2.  
  3. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
  4.     NSLog(@"image picked %@ with info %@", image, editingInfo);
  5.     NSData* jpegData = UIImageJPEGRepresentation (image,0.5);
  6.     EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
  7.     [jpegScanner scanImageData: jpegData];
  8.     EXFMetaData* exifData = jpegScanner.exifMetaData;
  9.     EXFJFIF* jfif = jpegScanner.jfif;
  10.     EXFTag* tagDefinition = [exifData tagDefinition: [NSNumber numberWithInt:EXIF_DateTime]];
  11.     //EXFTag* latitudeDef = [exifData tagDefinition: [NSNumber numberWithInt:EXIF_GPSLatitude]];
  12.     //EXFTag* longitudeDef = [exifData tagDefinition: [NSNumber numberWithInt:EXIF_GPSLongitude]];
  13.     id latitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLatitude]];
  14.     id longitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLongitude]];
  15.     id datetime = [exifData tagValue:[NSNumber numberWithInt:EXIF_DateTime]];
  16.     id t = [exifData tagValue:[NSNumber numberWithInt:EXIF_Model]];
  17. ....
  18. ....
  19.        
  20. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  21.  
  22.     // Try to get the original file.
  23.     NSURL *originalFile = [info objectForKey:UIImagePickerControllerMediaURL];
  24.     if (originalFile) {
  25.         NSData *fileData = [NSData dataWithContentsOfURL:originalFile];
  26.     }
  27. }
  28.        
  29. -(void) imagePickerController:(UIImagePickerController *)picker
  30.            didFinishPickingMediaWithInfo:(NSDictionary *)info
  31. {
  32.   NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  33.   if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
  34.     NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
  35.     if (url) {
  36.       ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
  37.       CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
  38.       // location contains lat/long, timestamp, etc
  39.       // extracting the image is more tricky and 5.x beta ALAssetRepresentation has bugs!
  40.     };
  41.     ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {
  42.       NSLog(@"cant get image - %@", [myerror localizedDescription]);
  43.     };
  44.     ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
  45.     [assetsLib assetForURL:url resultBlock:resultblock failureBlock:failureblock];
  46.   }
  47. }
  48.        
  49. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  50.  
  51.   id thumbnailView = [[[[[[[[[[picker.view subviews]
  52.                   objectAtIndex:0] subviews]
  53.                   objectAtIndex:0] subviews]
  54.                 objectAtIndex:0] subviews]
  55.                 objectAtIndex:0] subviews]
  56.               objectAtIndex:0];
  57.  
  58.   NSString *fullSizePath = [[[thumbnailView selectedPhoto] fileGroup] pathForFullSizeImage];
  59.   NSString *thumbnailPath = [[[thumbnailView selectedPhoto] fileGroup] pathForThumbnailFile];
  60.  
  61.   NSLog(@"%@ and %@", fullSizePath, thumbnailPath);
  62.  
  63. }
  64.        
  65. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  66.  
  67.     // Try to get the original file.
  68.     NSURL *originalFile = [info objectForKey:UIImagePickerControllerMediaURL];
  69.     if (originalFile) {
  70.         NSData *fileData = [NSData dataWithContentsOfURL:originalFile];
  71.     }
  72. }
clone this paste RAW Paste Data