0

我正在使用 Xamarin Forms 并希望加载保存在应用程序子文件夹中的图像。 编辑1:图像在运行时保存,由相机拍摄。

我想加载图像以便能够将其作为字节数组保存到数据库中。

我在加载图像时遇到问题。我传递了当前目录的路径,但它说它不存在。Android项目中的代码:

private bool ImageExists()
    {
        var imagePath = "accessEventPhoto.jpg";
        var documentsPath = Path.Combine(System.Environment.CurrentDirectory, imgFolder);
        var path = Path.Combine(documentsPath, imagePath);
        if (System.IO.File.Exists(path))
        {
            return true;
        }
        return false;
    }

编辑2:当我调试代码路径值是

"/ImagesFolder/accessEventPhoto.jpg" 

我在此调用中使用相机并设置保存照片的路径:

public async Task<string> OpenCameraResync()
{
    var picker = new MediaPicker(Forms.Context);
    if (!picker.IsCameraAvailable)
        System.Diagnostics.Debug.WriteLine("No camera!");
    else
    {
        var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions
        {
            Name = "accessEventPhoto.jpg",
            Directory = imgFolder
        });
        var mainActivity = Forms.Context as MainActivity;
        mainActivity.StartActivity(intent, OnActivityResult);
        ...
    }
    ...
}

如何找到图像的正确路径并加载它?

4

0 回答 0