【问题标题】:How to get location of Image from PHPhotoLibrary?如何从 PHPhotoLibrary 获取图像的位置?
【发布时间】:2017-12-04 13:17:39
【问题描述】:

由于不推荐使用 ALAssetLibrary Api,我们使用 PHPhotoLibrary 将图像保存到 PhotoAlbum

如果我们使用 ALAssetLibrary,我们可以获得保存图像的assetUri,但如果我们使用 PHPhotoLibrary,我们无法获得相同的结果。

assetUri 示例-

/Library/Developer/CoreSimulator/Devices/1ABD9386-B868-4B8D-9670-3F260D574569/data/Media/DCIM/100APPLE/

还有其他方法可以使用 PHPhotoLibrary 获得与上述相同的路径吗?

提前致谢

【问题讨论】:

    标签: xamarin.ios uiimage phphotolibrary


    【解决方案1】:

    AssetUri 不适用于 PHPhotoLibrary。

    我们可以改用request.PlaceholderForCreatedAsset.LocalIdentifier

    UIImagePickerController controller = new UIImagePickerController {
          SourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum,
          ImagePickerControllerDelegate = new PickerDelegate(),
          MediaTypes = new string[] { UTType.Image }
    };
    this.PresentViewController(controller, true, null);
    
    
    public class PickerDelegate: UIImagePickerControllerDelegate
    {
        public override void FinishedPickingImage(UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
        {
            PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(
                () => {
                    PHAssetChangeRequest request = PHAssetChangeRequest.FromImage(image);
                    string id = request.PlaceholderForCreatedAsset.LocalIdentifier;
                },
                (bool success, NSError error) => {
                }
            );
        }
    }
    

    参考

    How to get the URL of an image just added in PHPhotoLibrary

    Get URL of a newly created asset, iOS 9 style

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      相关资源
      最近更新 更多