【问题标题】:Save pictures that was taken through the app's camera to device's camera roll with metadata使用元数据将通过应用程序的相机拍摄的照片保存到设备的相机胶卷
【发布时间】:2017-02-06 19:14:47
【问题描述】:

我的应用有一个应用内相机,用户可以使用它拍照。

我希望当用户拍照时,图片将保存到设备的相机胶卷中。

我尝试过这样做:

UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil)

但后来我意识到它没有与图像的元数据(GPS 和捕获时间)一起保存。

我的问题是:如何将图像及其元数据保存到相机胶卷 (Swift 3)?

非常感谢!

【问题讨论】:

  • 你好这个问题可能对你有帮助:) stackoverflow.com/questions/38132357/…
  • @0ndre_ 这真的很复杂,我不明白什么与我的问题有关,什么与我的问题无关。有没有更简单,更清晰的方法来做到这一点?只需保存带有 GPS 和时间的照片。或者你能总结一下我应该怎么做吗?谢谢
  • 我在此处的回答 (stackoverflow.com/a/43375633/6431067) 显示了一个 Swift 解决方案,用于如何使用 Photos API 将图像保存到相机胶卷,同时保留对元数据所做的任何更改(特别是将 GPS/捕获时间添加到图片)。

标签: ios swift cocoa-touch swift3


【解决方案1】:

如果需要保存一些exif,可以使用SimpleExif pod

首先创建一个ExifContainer:

ExifContainer *container = [[ExifContainer alloc] init];

并用所有必需的数据填充它:

[container addUserComment:@"My data"];
[container addCreationDate:[NSDate dateWithTimeIntervalSinceNow:-10000000]];
[container addLocation:locations[0]];

然后您可以将此数据添加到图像中:

NSData *imageData = [imageToSave addExif:container];

然后保存

UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:imageData], nil, nil, nil);

【讨论】:

  • 那我该如何设置图片本身呢?
  • 我不明白你的问题,你能解释一下吗?
  • 在您添加的代码示例中,您没有添加 UIImage 本身。只是它的元数据
  • 在你的代码中: UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil); imageToSave 是 UIImage 本身我在 NSData *imageData = [imageToSave addExif:container];
猜你喜欢
  • 2013-04-03
  • 2014-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多