我的要求是在元数据中设置图片的描述,并将图片保存在文档目录中。
我发现了如何创建元数据,如果我将图像保存到照片库但我想将图像保存在文档目录中,元数据就会被设置。
请建议如何将元数据添加到我的图像并将图像保存在目录中。
我的代码:
NSMutableDictionary *tiffMetadata = [[NSMutableDictionary alloc] init];
[tiffMetadata setObject:@"This is my description" forKey:(NSString*)kCGImagePropertyTIFFImageDescription];
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
[metadata setObject:tiffMetadata forKey:(NSString*)kCGImagePropertyTIFFDictionary];
ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
NSData *imgData=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"IMG_0015" ofType:@"jpg"]];
[assetsLib writeImageDataToSavedPhotosAlbum:imgData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"%@",error.localizedDescription);
}
}];
如有任何建议,我们将不胜感激。 提前致谢。
最佳答案
许多应用程序将使用 ALAssets,然后使用完成 block 中生成的 URL 来执行其他操作。如果这不合适,您将需要更多地手动写入数据。 libexif.sourceforge.net/docs.html 可能对此有帮助,以下两个 SO 问题也有帮助:
How to write exif metadata to an image (not the camera roll, just a UIImage or JPEG)
从 CGImageSourceRef 到带有元数据的 CGImageDestinationRef 的步骤。
关于ios - 将元数据添加到我的图像并将其保存在文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23953189/