【问题标题】:Access URL of recently saved image最近保存的图像的访问 URL
【发布时间】:2023-03-27 15:40:01
【问题描述】:

我正在使用

UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

要保存图像,但我想知道它在哪里保存,意思是参考 URL 和保存图像的名称..

【问题讨论】:

标签: iphone ios ios4


【解决方案1】:

您可以使用 ALAssetsLibrary 获取它

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum:myCGImage metadata:nil completionBlock:^(NSURL* assetURL, NSError* error) 
{
      if (error.code == 0) {
         NSLog(@"URL %@", assetURL);
          [library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
              NSLog(@"Filename %@", [[asset defaultRepresentation] filename]);
          }
          failureBlock:^(NSError* error) {
             NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
            }];
       }else {
           NSLog(@"saved image failed.\nerror code %i\n%@", error.code, [error localizedDescription]);
       }
}];

【讨论】:

  • 我们将如何获取 URL,其给出 URL = (null) 和文件名 = (null)
  • 我运行它时得到这个:2013-01-24 19:53:31.839 speedClock[18363:907] URL assets-library://asset/asset.JPG?id=BB9BD7E2-076E -47DC-86B8-8C211C7ADDF3&ext=JPG 2013-01-24 19:53:31.888 speedClock[18363:907] 文件名 IMG_0990.JPG
  • 你确定你的CGImage没问题并且你已经添加了assetlibrary框架吗?
  • 我有一个问题..“myCGImage”是否与我的示例中的“image”相同..?
  • 你的回答帮助我解决了我的问题。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
相关资源
最近更新 更多