2012-01-29 26 views
4

我正嘗試使用地理標籤信息更新UIImage。我看着Saving Geotag info with photo on iOS4.1,這是我找到了對NSMutableDDictionary+ImageMetadata category的引用。不過,我不想保存到相冊中,但有一個UIImage傳遞。使用EXIF /地理標籤信息更新內存中的iOS UIImage

下面的代碼看起來像是製作了太多的圖像副本,並要求鏈接所有這些框架:CoreImage,AssetsLibrary,CoreMedia,ImageIO。

有什麼更高效,UIImage - >CIImage - >CGImage - >UIImage,可以採取的NSDictionary需要設置EXIF數據的屬性?

- (UIImage *)updateImage:(UIImage *)image location:(CLLocation *)location dateOriginal:(NSDate *)dateOriginal 
{ 
    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary:[image.CIImage properties]]; 

    // uses https://github.com/gpambrozio/GusUtils 
    [properties setLocation:location]; 
    [properties setDateOriginal:dateOriginal]; 

    CIImage *tempImage = [[CIImage alloc] initWithImage:image options:properties]; 
    CIContext *context = [CIContext contextWithOptions:nil];  
    UIImage *updatedImage = [UIImage imageWithCGImage:[context createCGImage:tempImage fromRect:tempImage.extent]]; 

    return updatedImage; 
} 

回答

0

看一看libexif:http://libexif.sourceforge.net/

你可能需要對圖像的字節數據傳遞到使用

UIImageJPEGRepresentation(image, quality) bytes]