Get image frames while recording video

385 Views Asked by At

I am creating an app which sampling photos while recording video.

Is there any event which I can subscribe to, to get a frame each x time?

In android there is a method OnPreviewCallback (or something like this)

2

There are 2 best solutions below

0
On

You would have to use PhotoCamera class

PhotoCamera class contains a method GetPreviewBufferArgb32 to get the preview frame into a byte array for furthur manipulations.

so, for say 5 frames per second you would need to make a timer and on timers tick you would have to call the method.

Refer these links, these would help you a lot

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202956(v=vs.105).aspx

http://msdn.microsoft.com/en-us/magazine/hh708750.aspx

http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.devices.photocamera(v=vs.105).aspx

0
On

I used the code below for one of my projects(QrCode scanning)


    private static readonly ManualResetEvent _pauseFramesEvent = new ManualResetEvent(true);
        private PhotoCamera _cam; 
   private Thread _yFramesThread;
private Dictionary<object, object> _hintDictionary;

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this._cam = new PhotoCamera();
            this._cam.Initialized += _cam_Initialized;
                this._pumpYFrames = true;
                this._isScanning = true;
            }


            CreateStandByTimer();
            this._yFramesThread = new Thread((PumpYFrames));
            this._yFramesThread.Start();
            base.OnNavigatedTo(e);

        }

    private void PumpYFrames()
            {
                var array = new byte[307200];
                while (_pumpYFrames)
                {
                    _pauseFramesEvent.WaitOne();
                    if (this._isScanning)
                    {
                        bool flag;
                        try
                        {
                            this._cam.GetPreviewBufferY(array);
                            flag = true;
                        }
                        catch
                        {
                            flag = false;
                        }
                        if (flag)
                        {
                            var source = new RGBLuminanceSource(array, 640, 480, false);
                            var binarizer = new HybridBinarizer(source);
                            var image = new BinaryBitmap(binarizer);
                            Reader reader = new QRCodeReader();
                            try
                            {
                                var results = reader.decode(image, _hintDictionary);
                                ProcessScan(results);

                            }
                            catch (Exception ex)
                            {//catch logic

                            }
                        }
                    }
                }
            }