How to take continuous photographs with XLabs
I am currently developing a cross platform application using a shared library capable of taking photos. I am using XLabs.Forms V2.0.5782 package for this application. I have successfully developed this simple application, but it allows me to take one image at a time .
I messed up the codes and I was able to take some pictures, but the problem is that the camera will close when I click "Use Photo" and reopen to take the next photo. I wanted that when I clicked Use Photo, the camera would re-open in place instead of closing and reopen.
Here is the code I did to take some pictures, but I know this is the wrong way to do it. It is in the event with the button pressed.
IDevice device = Resolver.Resolve<IDevice>();
IMediaPicker media = device.MediaPicker;
//More codes here
async void TakePicture(object sender, System.EventArgs e)
{
var options = new CameraMediaStorageOptions()
{
PercentQuality = 50,
DefaultCamera = CameraDevice.Rear,
MaxPixelDimension = 250
};
var cancel = false;
while (!cancel)
{
await media.TakePhotoAsync(options).ContinueWith(t =>
{
if (t.IsFaulted) //If there an error when taking photos
{
DisplayAlert("Error", "An error occurred when taking photo.\nPlease try again.", "OK");
}
else if (t.IsCanceled) //When the user click 'Cancel'
{
cancel = true;
}
else //When the user click 'Use Photo' - Here the part where the camera will close and reopen until user click 'Cancel'
{
var img = ImageSource.FromStream(() => t.Result.Source);
picList.Add(img);
}
});
}
if (picList.Count > 0)
{
scrollParent.IsVisible = true;
imageScroll.Children.Clear();
foreach (var pl in picList)
{
var image = new Image()
{
Source = pl,
HeightRequest = 150,
HorizontalOptions = LayoutOptions.Start,
Aspect = Aspect.AspectFit,
Margin = new Thickness()
{
Right = 10
}
};
imageScroll.Children.Add(image);
}
}
}
Is it possible for me to take multiple pictures using XLabs.Forms and is there a correct way? I've searched everywhere but couldn't find anything about it. Any help would be much appreciated. Thank!
Note:
-
I am using Visual Studio for Mac Preview 9 (7.0 build 2943)
-
I only tested on iPhones running iOS 10.2. Not tested on Android device yet
Here's a gif showing an example of my application. I think this will make you guys better understand what I want and what is going on.
Please note that 3 photos are taken in this example. The camera opens four times. After each photo, I clicked "Use Photo" in the lower right corner and when the camera opened for the 4th time, I clicked Undo in the lower left corner to stop the loop
Thank!
source to share
No one has answered this question yet
Check out similar questions: