首页 > 解决方案 > 将编辑后的照片与拍摄的照片一起保存

问题描述

我试图在我的一个应用程序中重复 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 仍然适用于任何图像。

标签: iosiphoneeditingphotos

解决方案


好的,问题已解决。问题是由于编辑后的图像具有“错误”的方向。根据 Apple 的文档,编辑后的图像必须正确定向(例如,根据它的方向标签),并且方向标签必须设置为 1,显然 CIImage 甚至在使用 .orient 方法后也没有这样做。


推荐阅读