Exifãªã©ã®ã¡ã¿ãã¼ã¿ãèªç±ã«æä½ããã«ã¯ã©ãããã
Best Albumã®éçºã§ãã£ã¨ãè¦ãããããã¨è¨ã£ã¦ãéè¨ã§ã¯ãªãã®ãExifæä½ãiOS4以éã§èªç±ã«ããããããã«ãªã£ãã¨ã¯ããããã¾ãã¾ã¨ã¾ã£ãè³æããªãã¦å¤§å¤ã ã£ãã®ã§ããããä½ã人ã®ããã«ã(iOS4.2ã§åä½ç¢ºèªããã¦ãã¾ã)
ã©ã¤ãã©ãª
ããã§ã¯ä¸è¨ã®ãã¬ã¼ã ã¯ã¼ã¯ãå©ç¨ãã¾ãã
#import <AssetsLibrary/AssetsLibrary.h> #import <ImageIO/ImageIO.h>
ãã©ãã©ã¤ãã©ãªã¸ã®ä¿å
ImagePickerControllerã§æ®å½±ãè¡ã£ã¦ããä¿åããå ´åãé常ã®æ¹æ³ã§ã¯Exifæ å ±ãä¿åããã¾ãããExifãä¿åãããå ´åã¯iOS4.1ãã追å ãããAssetsLibraryã®ã¡ã½ãããå©ç¨ãã¾ãã
ã¾ãã¯ã«ã¡ã©ï¼or ãã©ãã©ã¤ãã©ãªï¼ã®èµ·å
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init]; imgPicker.delegate = self; imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:imgPicker animated:YES]; [imgPicker release];
æ®å½±å¾ããªãªã¸ãã«ã¤ã¡ã¼ã¸ã¨ã¡ã¿ãã¼ã¿ãåå¾ã§ãã¾ãããã®æç¹ã§ããªãªã¸ãã«ã¤ã¡ã¼ã¸ã«ã¯ã¡ã¿ãã¼ã¿ã¯å«ã¾ãã¦ãã¾ããã®ã§ããã®ã¾ã¾ä¿åããã¨ã¡ã¿ãã¼ã¿ãè½ã¡ã¦ãã¾ãã¾ãã
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ [picker dismissModalViewControllerAnimated:YES]; // ãªãªã¸ãã«ã¤ã¡ã¼ã¸ UIImage *original = [info objectForKey:UIImagePickerControllerOriginalImage]; // ã¡ã¿ãã¼ã¿ NSMutableDictionary *metadata = (NSMutableDictionary *)[info objectForKey:UIImagePickerControllerMediaMetadata]; NSLog(@"%@", [metadata description]); // ãã®ã¡ã½ãããå©ç¨ããã¨ã¡ã¿ãã¼ã¿ã¯ä¿åãããªã UIImageWriteToSavedPhotosAlbum(original, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); }
ã¡ã¿ãã¼ã¿ãä¿åããå ´åã¯ãAssetsLibraryãå©ç¨ãã¾ãããã
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init]; [lib writeImageToSavedPhotosAlbum:original.CGImage metadata:metadata completionBlock:^(NSURL* url, NSError* error){ NSLog(@"Saved: %@<%@>", url, error); }]; [lib release];
AssetsLibraryãå©ç¨ããã¤ã¡ã¼ã¸ãã¼ã¿ã®èªã¿è¾¼ã¿
AssetsLibraryãå©ç¨ããå ´åã¯ç»åã¨ã¡ã¿ãã¼ã¿ãçµåãããrawãã¼ã¿ãåå¾å¯è½ã§ããç¬èªã®ImagePickerãéçºããå ´åã«ã¯ãã®æ¹æ³ã楽ã§ãã
NSURL *url = [NSURL URLWithString:@"assets-library://asset/asset.JPG?id=1000000179&ext=JPG"]; ALAssetsLibrary *lib = [[[ALAssetsLibrary alloc] init] autorelease]; [lib assetForURL:url resultBlock:^(ALAsset *asset){ ALAssetRepresentation *representation = [asset defaultRepresentation]; // raw data NSUInteger size = [representation size]; uint8_t *buff = (uint8_t *)malloc(sizeof(uint8_t)*size); if(buff != nil){ NSError *error = nil; NSUInteger bytesRead = [representation getBytes:buff fromOffset:0 length:size error:&error]; if (bytesRead && !error) { NSData *photo = [NSData dataWithBytesNoCopy:buff length:bytesRead freeWhenDone:YES]; } if (error) { NSLog(@"error:%@", error); [error release]; free(buff); } } } failureBlock:^(NSError *error){ NSLog(@"error:%@", error); }];
ã¤ã¡ã¼ã¸ãã¼ã¿ããã¡ã¿ãã¼ã¿ãèªã
ä¸è¨AssetsLibraryã§åå¾ã§ããNSDataããã¡ã¿ãã¼ã¿ãèªã¿ããå ´åã¯ãImage I/Oãã¬ã¼ã ã¯ã¼ã¯ãå©ç¨ãã¦èªããã¨ãã§ãã¾ãã
CGImageSourceRef cgImage = CGImageSourceCreateWithData((CFDataRef)photo, nil); NSDictionary *metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(cgImage, 0, nil); if (metadata) { NSLog(@"%@", [metadata description]); } else { NSLog(@"no metadata"); } [metadata release]; CFRelease(cgImage);
ã¤ã¡ã¼ã¸ãã¼ã¿ã¨ã¡ã¿ãã¼ã¿ã®çµå
ãã©ãã©ã¤ãã©ãªä¿åããrawãã¼ã¿ã®åå¾ä»¥å¤ã®æ¹æ³ã§ç»åã¨ã¡ã¿ãã¼ã¿ãçµåããå ´åã Image I/O ãå©ç¨ããã°å®ç¾ã§ãã¾ãã
ï¼kUTTypeJPEGã¯MobileCoreServices/UTCoreTypes.hã§å®ç¾©ããã¦ãã¾ãï¼
NSMutableData *concatData = [[NSMutableData alloc] init]; CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)concatData, kUTTypeJPEG, 1, nil); CGImageDestinationAddImage(dest, original.CGImage, (CFDictionaryRef)metadata); CGImageDestinationFinalize(dest); CFRelease(dest);
ã¡ã¿ãã¼ã¿ã®æ¸ãæãã¯Dictionaryãç´æ¥å¤æ´ããã°OKã§ãã
ããã ãæ¼ããã¦ããã°å¤§æµã®å¦çã¯å¤§ä¸å¤«ã§ãããã