Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created July 31, 2012 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/3213616 to your computer and use it in GitHub Desktop.
Save hisasann/3213616 to your computer and use it in GitHub Desktop.
Exifを付与し、/tmpに画像を保存するサンプルコード
- (void)setExifInfo:(UIImage *)image {
CGImageSourceRef cgImage = CGImageSourceCreateWithData((__bridge CFDataRef) UIImageJPEGRepresentation(image, 1), NULL);
NSMutableDictionary *exifDict = [[NSMutableDictionary alloc] init];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
NSString *original = [outputFormatter stringFromDate:[NSDate date]];
[exifDict setObject:original forKey:(__bridge NSString *) kCGImagePropertyExifDateTimeOriginal];
[exifDict setObject:original forKey:(__bridge NSString *) kCGImagePropertyExifDateTimeDigitized];
NSMutableData *imageData = [[NSMutableData alloc] init];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) imageData, CGImageSourceGetType(cgImage), 1, nil);
CGImageDestinationAddImageFromSource(destination, cgImage, 0, (__bridge CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
exifDict, (__bridge NSString *) kCGImagePropertyExifDictionary, nil]);
CGImageDestinationFinalize(destination);
NSString *exportPath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), @"exportWithExif.jpg"];
[imageData writeToFile:exportPath atomically:YES];
CFRelease(cgImage);
CFRelease(destination);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment