首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法保存元数据编辑到相机卷的“方位= 6”的水平方向。

无法保存元数据编辑到相机卷的“方位= 6”的水平方向。
EN

Stack Overflow用户
提问于 2019-04-09 00:53:49
回答 1查看 183关注 0票数 0

我正在尝试编辑相机滚动照片的元数据。

但是,如果您试图在编辑元数据后覆盖照片,总是会给出以下错误:

'Error Domain=NSCocoaErrorDomain Code=-1“操作无法完成。(可可错误-1.)'

这发生在照片,如景观图像(方向标签'6')。

对于肖像图像(方向标签为'1'),可以正确地覆盖和保存照片。

如果您使用UIImageJPEGRepresentation (Image1.0)进行解码,则可以覆盖和保存景观图像。

但我不想降低图像的质量,所以我正在寻找另一种方式。

复制步骤:

  1. 将相机的照片保存在“文档/…”下面。
  2. 编辑一张照片的元数据。(从现在起,在文件/)下
  3. 获取资产"requestContentEditingInputWithOptions ()“。
  4. 获取“步骤2”照片的URL,并使用“CGImageSourceCreateWithURL()”获取CGImageSourceCreateWithURL
  5. 通过使用‘CGImageDestinationRef ()’指定contentEditingOutput.renderedContentURL来获取CGImageDestinationCreateWithURL。
  6. 将CGImageSourceRef、CGImageDestinationRef和元数据设置为CGImageDestinationAddImageFromSource。
  7. 使用CGImageDestinationRef保存CGImageDestinationFinalize。
  8. 创建PHAadjustmentData。将元数据设置为“数据”。
  9. 在AdjustmentData中设置setAdjustmentData
  10. 在changeRequestForAsset of PHPhotoLibrary中设置集合。'PHAssetChangeRequest *changeRequestForAsset= PHAssetChangeRequest changeRequestForAsset:→;‘
  11. 'request.contentEditingOutput = contentEditingOutput;‘
  12. “完成”是一个错误。以下错误:“error Domain=NSCocoaErrorDomain Code=-1”操作无法完成。(可可错误-1。)

遵循代码的

代码语言:javascript
复制
    - (void)replaceMetadataIntoPhoto:(NSInteger)index metadata:(NSDictionary *)metadata 
    { 
        PHAsset *asset = _assetsList[index]; 
   
        [asset requestContentEditingInputWithOptions:nil 
                                   completionHandler:^(PHContentEditingInput *_Nullable contentEditingInput, NSDictionary *_Nonnull info) { 
   
                                       NSURL *url = [contentEditingInput fullSizeImageURL]; 
                                       CGImageSourceRef sourceImage = CGImageSourceCreateWithURL((__bridge CFURLRef)url, nil); 
   
                                       PHContentEditingOutput *contentEditingOutput = [[PHContentEditingOutput alloc] initWithContentEditingInput:contentEditingInput]; 
   
                                       CGImageDestinationRef outputDestination = CGImageDestinationCreateWithURL((__bridge CFURLRef)contentEditingOutput.renderedContentURL, CGImageSourceGetType(sourceImage), 1, NULL); 
   
                                       CGImageDestinationAddImageFromSource(outputDestination, sourceImage, 0, (__bridge CFDictionaryRef)metadata); 
   
                                       CGImageDestinationFinalize(outputDestination); 
                                       CFRelease(sourceImage); 
                                       CFRelease(outputDestination); 
   
                                       PHAdjustmentData *adjustmentData = 
                                       [[PHAdjustmentData alloc] initWithFormatIdentifier:@"hogehoge" 
                                                                            formatVersion:@"1.0" 
                                                                                     data:[NSKeyedArchiver archivedDataWithRootObject:@{@"metadata": metadata}]]; 
   
                                       [contentEditingOutput setAdjustmentData:adjustmentData]; 
   
                                       [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
                                           PHAssetChangeRequest *request = [PHAssetChangeRequest changeRequestForAsset:asset]; 
                                           request.contentEditingOutput = contentEditingOutput; 
   
                                       }   completionHandler:^(BOOL success, NSError *error) { 
                                             if (error) { 
                                                  DBGLog(@"error=%@", error); 
                                              } 
   
                                       }]; 

预期结果:

能够覆盖和保存带有编辑后的元数据的风景图像。

实际结果:

覆盖保存失败。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-17 01:41:46

我从苹果的反馈助理那里得到了答案。下面是一段引语。

请参考https://developer.apple.com/documentation/photokit/phcontenteditingoutput/1518655-renderedcontenturl重要的编辑资产内容,必须包含(或“烘焙”)资产的预定方向。也就是说,您在输出图像或视频文件中写入的定向元数据(如果有的话)必须声明“向上”方向,而在没有方位元数据的情况下,图像或视频数据必须向上显示。如果要在EXIF或其他文件中重写定向元数据,则应尝试创建新资产,而不是使用PHContentEditingOutput。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55583659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档