2013-12-13 108 views
0

我正在創建一個應用程序,可在錄製視頻時對照片進行採樣。錄製視頻時獲取圖像幀

是否有任何我可以訂閱的事件,每x次獲取一幀?

在Android中有一個方法OnPreviewCallback(或像這樣)

回答

4

你將不得不使用PhotoCamera類

PhotoCamera類包含一個方法GetPreviewBufferArgb32得到預覽框成字節數組furthur操作。

因此,比如說每秒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

+0

感謝它幫助! – user3099571

+0

歡迎您... – Archana

0

我用下面的代碼爲我的項目之一(QR碼掃描)


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 

          } 
         } 
        } 
       } 
      }