将图像元数据写入iOS中的JPG / PNG文件

时间:2011-03-16 19:45:03

标签: iphone ios uiimage metadata

有没有办法将UIImage写入JPG / PNG文件,然后将元数据附加到它?我知道你可以使用:

writeImageDataToSavedPhotosAlbum:元数据:completionBlock

在保存的照片中执行此操作,但是如何直接对文件执行相同的操作?我似乎无法找到任何方法来做到这一点。我知道UIImagePNGRepresentation()和UIImageJPGRepresentation()将为您提供可用于编写文件的NSData,但无法在文件中追加/替换元数据。

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

看起来像duplicate

要向UIImage添加元数据,您可以使用ImageIO框架您可以从UIImage创建CGImageDestination对象,使用CGImageDestinationSetProperties向其添加元数据,然后从中获取原始数据(包括压缩图像和元数据)。

答案 1 :(得分:-7)

@rekle 看看这个代码是用于将照片写入文件

NSData *imageData = UIImagePNGRepresentation(self.imageView.image);
            NSData *myImage=[[NSData alloc]initWithData:imageData];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSLog(@"%@",documentsDirectory);

            NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",camtitle.text]];
            [myImage writeToFile:fullPathToFile atomically:YES];
            NSLog(@"%@",fullPathToFile);
            [myImage release

];

相关问题