0

私は現在、System.Graphics.DrawEllipse を使用していくつかの楕円を描画するアプリケーションを開発しました。これは C# で正常に動作します。

これを統合して、それぞれの目に異なる画像を提供することにより、ステレオ イメージング (3D) を使用して特定の楕円を異なる目に表示したいと考えています。 NVIDIA 3D とシャッター グラスを使用したステレオ/3D 方式で。

This questionは、3Dを使用してc#で立体画像を表示する方法の答えを提供しますが、Surfaceクラスを利用しています。インターネットでよく検索しましたが、図形を描画する方法や、画像 (ビットマップ) の代わりに既に描画されている図形を使用する方法が見つかりませんでした。

どんな助けでも大歓迎です。ありがとうございました。

4

2 に答える 2

0

directx と GDI の間で対話する直接的な方法はありません。この同じ問題に遭遇したとき、GDI からメモリにバイトを準備してから、direct3D に戻すことにしました。以下にコードを追加しました。私のプロジェクトで使用されていると思うので、うまくいくはずです:)

これは directx11 用であることに注意してください (簡単に変換できるはずです)。また、*B*GRA テクスチャ フォーマットの使用は意図的なものであり、それ以外の場合は色が反転します。

さらにパフォーマンスが必要な場合は、DirectDraw を検討することをお勧めします。

    private byte[] getBitmapRawBytes(Bitmap bmp)
{
    Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    System.Drawing.Imaging.BitmapData bmpData =
        bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

    // Get the address of the first line.
    IntPtr ptr = bmpData.Scan0;

    // Declare an array to hold the bytes of the bitmap.
    int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
    byte[] rgbValues = new byte[bytes];

    // Copy the RGB values into the array.
    System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

    // Unlock the bits.
    bmp.UnlockBits(bmpData);
    return rgbValues;
}


/// <summary>
/// The bitmap and the texture should be same size.
/// The Texture format should be B8G8R8A8_UNorm
/// Bitmap pixelformat is read as PixelFormat.Format32bppArgb, so if this is the native format maybe speed is higher?
/// </summary>
/// <param name="bmp"></param>
/// <param name="tex"></param>
public void WriteBitmapToTexture(Bitmap bmp, GPUTexture tex)
{
    System.Diagnostics.Debug.Assert(tex.Resource.Description.Format == Format.B8G8R8A8_UNorm);

    var bytes = getBitmapRawBytes(bmp);
    tex.SetTextureRawData(bytes);

}
于 2013-08-01T08:12:56.753 に答える