[英]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.