2009-09-28 9 views
7

基本的には、WPFでピクセルを書き込み、WPFでビットマップを更新して表示できるGDIタイプの機能がWPFに必要です。注:私は、マウスの動きに応じてピクセルを更新することで、オンザフライでビットマップをアニメーション化できる必要があります。私はInteropBitmapがこれには最適だと読んだことがあります。メモリ内のピクセルに書き込んでメモリ位置をビットマップにコピーすることができますが、良い例はありません。wpf 2d高性能グラフィック

InteropBitmapや他のいくつかのクラスを使用してWPFで高性能2Dグラフィックスを使用するための優れたリソース、チュートリアル、ブログを知っている人はいますか?

+0

ピクセル単位の処理を行う場合は、実際にWPFが必要ですか? – MusiGenesis

+0

残りのアプリケーションのコンテキストはWPFです。 – Klay

答えて

4

は、ここで私が見つけたものです:

は、私がイメージをサブクラスクラスを作成しました。

public class MyImage : Image { 
    // the pixel format for the image. This one is blue-green-red-alpha 32bit format 
    private static PixelFormat PIXEL_FORMAT = PixelFormats.Bgra32; 
    // the bitmap used as a pixel source for the image 
    WriteableBitmap bitmap; 
    // the clipping bounds of the bitmap 
    Int32Rect bitmapRect; 
    // the pixel array. unsigned ints are 32 bits 
    uint[] pixels; 
    // the width of the bitmap. sort of. 
    int stride; 

public MyImage(int width, int height) { 
    // set the image width 
    this.Width = width; 
    // set the image height 
    this.Height = height; 
    // define the clipping bounds 
    bitmapRect = new Int32Rect(0, 0, width, height); 
    // define the WriteableBitmap 
    bitmap = new WriteableBitmap(width, height, 96, 96, PIXEL_FORMAT, null); 
    // define the stride 
    stride = (width * PIXEL_FORMAT.BitsPerPixel + 7)/8; 
    // allocate our pixel array 
    pixels = new uint[width * height]; 
    // set the image source to be the bitmap 
    this.Source = bitmap; 
} 

WriteableBitmapにはWritePixelsというメソッドがあり、このメソッドは符号なしintの配列をピクセルデータとして受け取ります。イメージのソースをWriteableBitmapに設定しました。今、ピクセルデータを更新してWritePixelsを呼び出すと、イメージが更新されます。

私は、ビジネスポイントデータを別のオブジェクトにポイントリストとして保存します。リスト上で変換を実行し、変換された点でピクセルデータを更新します。この方法では、ジオメトリオブジェクトからのオーバーヘッドはありません。

私はポイントを、ブレーゼンハムのアルゴリズムと呼ばれるものを使って描いた線で結びます。

この方法は、極端にです。マウスの動きに対応して、約5万ポイント(および接続ライン)を更新しています。

1

ここにはWeb cameras with InteropBitmapのブログ投稿があります。 InteropBitmapの使い方を示す完全なソースコードプロジェクトが含まれています。

+0

この引用をブログから愛してください: "...イメージングの点でのWPFのパフォーマンスは悪いです"。 – MusiGenesis

関連する問題