我目前已经开发了一个应用程序,它使用System.Graphics.DrawEllipse绘制几个椭圆,在c#中工作得很好。
现在,我想通过为每只眼睛提供不同的图像来将某些椭圆显示给不同的眼睛。我安装了DirectX SDK和SharpDX,我想使用生成的椭圆(2D),并使用NVIDIA3D和快门眼镜以立体声/ 3D方式显示它。
This question给出了如何使用3D在c#中显示立体图像的答案,但它使用了Surface。我在网上搜索了很多,但找不到绘制形状的方法,也无法使用已经绘制的形状而不是图像(位图)。
任何帮助都是非常感谢的。谢谢。
发布于 2013-08-24 10:36:24
我的工作方式是将创建的每个椭圆(通过图形)保存在位图中,将每个位图添加到位图列表中,并将这些位图加载到Direct3D曲面列表中,然后按索引访问我想要的任何曲面。
我希望这对其他人也有帮助。
发布于 2013-08-01 08:12:56
在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);
}https://stackoverflow.com/questions/17955020
复制相似问题