如何从PHPhotoLibrary获取Image的位置?

时间:2017-12-04 13:17:40

标签: xamarin.ios uiimage phphotolibrary

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

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

示例对于assetUri -

/库/开发商/ CoreSimulator /设备/ 1ABD9386-B868-4B8D-9670-3F260D574569 /数据/媒体/ DCIM / 100APPLE /

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

先谢谢

1 个答案:

答案 0 :(得分:0)

PHPhotoLibrary不提供AssetUri。

我们可以改为使用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