About continuous shooting method of camera application

TS44 81 Reputation points
2020-11-30T23:03:09.217+00:00

With the code below, I started the camera app and took a picture, but once I took a picture, the app closed. What should I do when taking multiple shots?

private async void OnImageClicked()
{

    try
    {

        await Plugin.Media.CrossMedia.Current.Initialize();

        if (!Plugin.Media.CrossMedia.Current.IsCameraAvailable || !Plugin.Media.CrossMedia.Current.IsTakePhotoSupported)
        {
            return;
        }

        DateTime dt = DateTime.Now;
        string result = dt.ToString("yyyyMMddHHmmss");
        result += ".jpg";

        var file = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {

            Name = result

        });

        if (file == null)
            return;

        var bytes = new Queue<byte>();
        using (var s = file.GetStream())
        {
            var length = s.Length;
            int b;
            while ((b = s.ReadByte()) != -1)
                bytes.Enqueue((byte)b);
        }

        File.Copy(file.Path, "/Pic");

        PicPoint.Add(result);

        file.Dispose();

    }
    catch (Exception)
    {


    }

}
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,284 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 67,631 Reputation points Microsoft Vendor
    2020-12-01T05:15:27.637+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Xam.Plugin.Media do not have take multiple shots function, you can open an feature request in following url.

    https://github.com/jamesmontemagno/MediaPlugin/issues

    You can execute the TakePhotoAsync multiple times like following code like this thread.
    https://forums.xamarin.com/discussion/104140/how-to-take-multiple-pictures-using-camera-in-xamarin-ios

       for (int i = 0; i < 3; i++)  
                       {  
                           var file = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions  
                           {  
         
                               Name = result  
         
                           });  
                       }  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments