ios - 将编辑后的照片与拍摄的照片一起保存
问题描述
我试图在我的一个应用程序中重复 Apple 文档中的示例,即我拍摄照片,对其进行编辑,并希望将它们与一些调整数据一起保存在一个资产中。苹果提供以下代码:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
// Make a change request for adding an asset.
PHAssetChangeRequest *changeRequest =
[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:originalJPEGFileURL];
// Make a content editing output for use with the change request.
PHObjectPlaceholder *placeholder = changeRequest.placeholderForCreatedAsset;
PHContentEditingOutput *contentEditingOutput =
[[PHContentEditingOutput alloc] initWithPlaceholderForCreatedAsset:placeholder];
// Apply content adjustments to the newly created asset.
contentEditingOutput.adjustmentData = adjustmentData;
[adjustedJPEGData writeToURL:contentEditingOutput.renderedContentURL atomically:YES];
changeRequest.contentEditingOutput = contentEditingOutput;
} completionHandler:^(BOOL success, NSError *error) {
if (!success) NSLog(@"Can't create asset: %@", error);
}];
不幸的是,我不断收到错误代码-1。是否有人在资产刚刚创建时成功地将编辑后的图像与原始图像一起存储?
更新 1:仅当资产包含深度信息时才会发生这种情况:-/
更新2:嗯,事情变得更糟了。我已经在我的 iPhone 上尝试了名为 UsingPhotosFramework 的 Apple 应用程序,但它也不起作用。我还注意到我可以使用照片进行编辑,一旦我对我的资产和 Apple 的应用程序进行了一些编辑。当资产恢复到原点时(意味着没有更多的调整数据或 fullSizePhoto 存在)两个应用程序都停止工作。Snapseed 仍然适用于任何图像。
解决方案
好的,问题已解决。问题是由于编辑后的图像具有“错误”的方向。根据 Apple 的文档,编辑后的图像必须正确定向(例如,根据它的方向标签),并且方向标签必须设置为 1,显然 CIImage 甚至在使用 .orient 方法后也没有这样做。
推荐阅读
- c - “错误:程序中的流浪'\ 344'”是什么意思?
- c# - 我要实时绘图,不耽误
- apache-spark - PySpark 和时间序列数据:如何巧妙地避免日期重叠?
- selenium - 如何将对象作为参数传递给 Html 单元驱动程序
- javascript - 在 Vue.js 中构建后出现 JSON 错误的空白页面
- php - 如何从表单输入字段中将月份添加到日期
- amazon-s3 - S3 / AWS 上的清理
- discord.js - 将命令锁定到特定角色
- javascript - 如果我的值需要根据之前的值进行更新,我该如何编写纯函数式代码?
- django-models - Django 使用特定子句过滤 ManyToManyField