我尝试从我使用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();
});
}
}
}
答案 0 :(得分:0)