简体   繁体   English

使用 Xam.Plugin.Media 拍摄和存储用户照片的强制性要求

[英]Compulsary requirement to take and store users photo using Xam.Plugin.Media

I have a PCL type app and I'm using the Xam.Plugin.Media plugin.我有一个 PCL 类型的应用程序,我正在使用Xam.Plugin.Media插件。 I need it to ensure a user submits a photo from the camera before they can continue.我需要它来确保用户在继续之前从相机提交照片。

To do this I show the camera page from a button click event and I want to ensure that in case the user cancels out of this that the app launches the camera again, this would repeat until a photograph is stored.为此,我从按钮单击事件中显示相机页面,并且我想确保如果用户取消此应用程序再次启动相机,这将重复直到存储照片。

Currenty my app falls in the onActivityResumed method of the MainApplication file when the user cancels out of the camera当前,当用户取消相机时,我的应用程序属于MainApplication文件的onActivityResumed方法

Attached photo of my code, My code .附上我的代码照片,我的代码

 private async void TakePicture()
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await App.Current.MainPage.DisplayAlert("No Camera", ":( No camera available.", "Aceptar");
            }



            file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory = "Sample",
                Name = "test.jpg",
                PhotoSize = PhotoSize.Small,
            });

            //IsRunning = true;


            if (file != null)
            {
                ImageSource = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return stream;
                });
            }

            IsRunning = false;
        }

Aside from the fact that it is usually a bit of a UX issue to force a user into anything nowadays, the question still has some merits.除了现在强迫用户做任何事情通常是一个用户体验问题之外,这个问题仍然有一些优点。

this is the approach that I would consider, it involves recursion.这是我会考虑的方法,它涉及递归。

    private async void TakePicture()
    {
        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await App.Current.MainPage.DisplayAlert("No Camera", ":( No camera available.", "Aceptar");
        }

        file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {
            Directory = "Sample",
            Name = "test.jpg",
            PhotoSize = PhotoSize.Small,
        });

        //IsRunning = true;

        if (file != null)
        {
            ImageSource = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return stream;
            });
        }
        else
        {
            // Recursion - I believe that this would continue until the file is not null, then it would carry on.
            TakePicture();
        }

        IsRunning = false;
    }

I can't say I use recursion that often, but I think it might do the trick here.我不能说我经常使用递归,但我认为它可能在这里起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Xam.Plugin.Media 从图片库中添加照片? - How to add photo from gallery in Image with Xam.Plugin.Media? 无法使用Xam.Plugin.Media插件 - Can't use Xam.Plugin.Media plugin 使用xam.plugin.media将映像上传到服务器(后端)时收到错误请求 - Am getting Bad Request while uploading an Image to the server (backend) , am using xam.plugin.media 尝试使用Xam.Plugin.Media打开相机时抛出异常 - Exception throw out when trying to open the camera using Xam.Plugin.Media 将来自 Xam.Plugin.Media 5.0.1 的 imageSource 转换为 Xamarinforms 中的字节数组? - Convert imageSource coming from Xam.Plugin.Media 5.0.1 to byte array in Xamarinforms? Xam.Plugin.Media的方法“ TakePhotoAsync”在Xamarin.Forms的平台WinPhone上返回null - Method “TakePhotoAsync” of Xam.Plugin.Media return null on platform WinPhone in Xamarin.Forms Xamarin Forms 和 xam.plugin.media:无法解析对 Xamarin.Essentials.Permissions 的引用 - Xamarin Forms and xam.plugin.media: could not resolve reference to Xamarin.Essentials.Permissions 如何在xam.plugin.settings中存储整数值? - How can I store integer values in xam.plugin.settings? Media.Plugin仅适用于Google Photo - Media.Plugin working only with Google Photo 拍摄第二张照片时 Xamarin 媒体插件崩溃 - Xamarin Media Plugin Crashes when second photo is taken
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM