Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

About continuous shooting method of camera application

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)
    {


    }

}

Answers

Sign In or Register to comment.