Created
August 3, 2012 02:42
-
-
Save hisasann/3243796 to your computer and use it in GitHub Desktop.
Exifを付与しNSDataを作成するサンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSData *)setExifInfoData:(UIImage *)image date:(NSString *)date { | |
CGImageSourceRef cgImage = CGImageSourceCreateWithData((__bridge CFDataRef) UIImageJPEGRepresentation(image, 1), NULL); | |
NSMutableDictionary *exifDict = [[NSMutableDictionary alloc] init]; | |
if ([StringUtil isNilToEmpty:date]) { | |
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]; | |
} else { | |
[exifDict setObject:date forKey:(__bridge NSString *) kCGImagePropertyExifDateTimeOriginal]; | |
[exifDict setObject:date 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); | |
CFRelease(cgImage); | |
CFRelease(destination); | |
return imageData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment