未处理的异常:Android.Content.Res.Resources + NotFoundException:发生<超时超过获取异常详细信息>

时间:2019-07-06 15:02:23

标签: c# xamarin.forms

我尝试从我使用Xamarin-forms,visual studio 2017开发的应用程序从画廊中挑选一张图片。选择完一张图片后,我一直遇到这个错误。与使用相机拍摄照片时相同。 我尝试调试它。但是我无法从中得到任何具体信息。 到var mediaFile时崩溃了

using Plugin.Media;
using Plugin.Media.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App11.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Levels : ContentPage
    {
        public Levels ()
        {
            InitializeComponent ();
        }

        private async void TakePhoto_Clicked(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("camera", "not supported", "OK");
                return;
            }

            var mediaFile= await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
            {
                Directory = "Sample",
                Name = "test.jpg"
            });

            if (file == null)
                return;

            await DisplayAlert("File Location", file.Path, "OK");

            image.Source = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return stream;
            });

        }

        private async void FromPhone_Clicked(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("No pickphoto", "Not available", "OK");
                return;
            }

            var mediaFile = await CrossMedia.Current.PickPhotoAsync();

            if (mediaFile == null)
                return;

            image.Source = ImageSource.FromStream(() =>
            {
                return mediaFile.GetStream();
            });
        }
    }
}

1 个答案:

答案 0 :(得分:0)

请使用以下有关拍照的代码:

moduleB

以下是您可以查看的示例:

https://github.com/jamesmontemagno/MediaPlugin