【问题标题】:Unhandled Exception: Android.Content.Res.Resources+NotFoundException: <Timeout exceeded getting exception details> occurred未处理的异常:Android.Content.Res.Resources+NotFoundException:<Timeout exceeded getting exception details> 发生
【发布时间】:2019-07-06 15:02:23
【问题描述】:

我尝试从我使用 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();
            });
        }
    }
}

【问题讨论】:

    标签: c# xamarin.forms


    【解决方案1】:

    拍照请输入以下代码:

     private async void Takephoto_Clicked(object sender, EventArgs e)
        {
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                DisplayAlert("No Camera", ":( No camera available.", "OK");
                return;
            }
    
            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory = "Test",
                SaveToAlbum = true,
                CompressionQuality = 75,
                CustomPhotoSize = 50,
                PhotoSize = PhotoSize.MaxWidthHeight,
                MaxWidthHeight = 2000,
                DefaultCamera = CameraDevice.Front
            });
    
            if (file == null)
                return;
    
            DisplayAlert("File Location", file.Path, "OK");
    
            image.Source = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return stream;
            });
        }
    

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

    https://github.com/jamesmontemagno/MediaPlugin

    【讨论】:

      猜你喜欢
      • 2019-08-30
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      相关资源
      最近更新 更多