2009-08-05 25 views
1

私は提供されたライブラリを使用して制御する特別なビデオカメラ(GigEVisionプロトコルを使用)を持っています。フレーム受信イベントを購読し、IntPtr経由でフレームデータにアクセスすることができます。WPFで生のフレームからビデオをレンダリングするには?

私の古いWinFormsアプリケーションでは、データからBitmapオブジェクトを作成し、それをPictureBox Imageに設定するか、PictureBoxハンドルを提供されたライブラリの関数に渡して直接描画しますエリア。

WPFで同様のことを行うには、最善の方法と最速の方法は何ですか?ビデオカメラは30〜100 fpsのどこでも動作します。

編集(1):

をフレーム受信したイベントが、それはスレッド間で作業しなければならないUIスレッドではないので。

編集(2):

IはWriteableBitmapを使用して解決策を見つけた:上記で

void camera_FrameReceived(IntPtr info, IntPtr frame) 
{ 
    if (VideoImageControlToUpdate == null) 
    { 
     throw new NullReferenceException("VideoImageControlToUpdate must be set before frames can be processed"); 
    } 

    int width, height, size; 
    unsafe 
    { 
     BITMAPINFOHEADER* b = (BITMAPINFOHEADER*)info; 

     width = b->biWidth; 
     height = b->biHeight; 
     size = (int)b->biSizeImage; 
    } 
    if (height < 0) height = -height; 

     //Warp space-time 
     VideoImageControlToUpdate.Dispatcher.Invoke((Action)delegate { 
     try 
     { 
      if (VideoImageControlToUpdateSource == null) 
      { 
       VideoImageControlToUpdateSource = 
        new WriteableBitmap(width, height, 96, 96, PixelFormats.Gray8, BitmapPalettes.Gray256); 
      } 
      else if (VideoImageControlToUpdateSource.PixelHeight != height || 
        VideoImageControlToUpdateSource.PixelWidth != width) 
      { 
       VideoImageControlToUpdateSource = 
        new WriteableBitmap(width, height, 96, 96, PixelFormats.Gray8, BitmapPalettes.Gray256); 
      } 

      VideoImageControlToUpdateSource.Lock(); 

      VideoImageControlToUpdateSource.WritePixels(
       new Int32Rect(0, 0, width, height), 
       frame, 
       size, 
       width); 

      VideoImageControlToUpdateSource.AddDirtyRect(new System.Windows.Int32Rect(0, 0, width, height)); 
      VideoImageControlToUpdateSource.Unlock(); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.ToString()); 
     } 
    }); 
} 

VideoImageControlToUpdateがWPF画像制御です。

私は、Codeplexで見つかったVideoRendererElementが高速であると信じています。

答えて

0

ベストな方法: WriteableBitmap.WritePixels(...、のIntPtrソース、...)

最速の方法: 使用WICとのIntPtrアンマネージメモリ内のすべての操作。しかし、なぜこの場合WPFを使うのですか?そのような種類のパフォーマンスが必要な場合は、DirectXオーバーレイの使用を検討してください。

+0

DirectXを使用した例へのリンクがありますか? –

+0

DirectXは行く方法です - それはスーパーコンプレックスではありません。 DIrectXライブラリが必要です(C#の場合、いくつかのオープンソースのものがあります)。そしていくつかの基本的な知識が必要です。パフォーマンスの岩;) – TomTom

関連する問題