繁体   English   中英

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

[英]Write image metadata to JPG/PNG file in iOS

有什么方法可以将UIImage写入JPG / PNG文件,然后将元数据附加到其中? 我知道您可以使用:

writeImageDataToSavedPhotosAlbum:metadata:completionBlock

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

有任何想法吗?

看起来像重复的

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

@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

];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM