【问题标题】:Write image metadata to JPG/PNG file in iOS在 iOS 中将图像元数据写入 JPG/PNG 文件
【发布时间】:2011-07-16 21:31:36
【问题描述】:

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

writeImageDataToSavedPhotosAlbum:metadata:completionBlock

要在保存的照片中执行此操作,但是如何直接对文件执行相同操作?我似乎找不到任何方法来做到这一点。我知道 UIImagePNGRepresentation() 和 UIImageJPGRepresentation() 会给你 NSData ,你可以用它来写文件,但是没有办法附加/替换文件中的元数据。

有什么想法吗?

【问题讨论】:

  • 也许这个对类似问题的回答会有所帮助:stackoverflow.com/questions/5125323/…
  • 编写一个自定义的 PNG 导出器需要 3 天时间,反正 :)
  • 你应该看看 ImageIO 框架。您可以使用CGImageDestinationSetProperties 将元数据添加到CGImageDestination,然后从中获取原始数据

标签: iphone ios uiimage metadata


【解决方案1】:

看起来像duplicate

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

【讨论】:

    【解决方案2】:

    @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
    

    ];

    【讨论】:

    • 这并没有解决如何将元数据添加到文件的问题
    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 2013-02-19
    • 2014-03-17
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多