如何在不使用xamarin形式的图片库的情况下拍摄实时照片?

时间:2019-04-15 12:59:51

标签: xamarin.forms

现在,我正在尝试通过按钮拍摄照片,我将其发送到数据库而不将其保存到图库中,但我的限制是用户不能从图库中拍摄照片,这应该是实时的,那我该怎么办呢?

1 个答案:

答案 0 :(得分:0)

使用Media插件

takePhoto.Clicked += async (sender, args) =>
{
    await CrossMedia.Current.Initialize();

    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 = "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;
    }); 
};