0

我正在创建一个在录制视频时对照片进行采样的应用程序。

有没有我可以订阅的事件,每次获取一个框架?

在android中有一个方法OnPreviewCallback(或类似的东西)

4

2 回答 2

4

您将不得不使用 PhotoCamera 类

PhotoCamera 类包含一个 GetPreviewBufferArgb32 方法,用于将预览帧放入字节数组以进行进一步操作。

因此,例如每秒 5 帧,您需要制作一个计时器,并且在计时器滴答时您必须调用该方法。

参考这些链接,这些会对你有很大帮助

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

于 2013-12-13T14:22:06.353 回答
0

我将下面的代码用于我的一个项目(QrCode 扫描)


    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

                            }
                        }
                    }
                }
            }
于 2013-12-13T14:43:26.787 回答