Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将System.Graphics.DrawEllipse显示/实现为DirectX 3D曲面?!c#_C#_Drawing_Directx_Rendering_Graphics2d - Fatal编程技术网

将System.Graphics.DrawEllipse显示/实现为DirectX 3D曲面?!c#

将System.Graphics.DrawEllipse显示/实现为DirectX 3D曲面?!c#,c#,drawing,directx,rendering,graphics2d,C#,Drawing,Directx,Rendering,Graphics2d,我目前开发了一个应用程序,它使用System.Graphics.DrawEllipse绘制了几个椭圆,在c#中效果很好 现在我想将其集成,以便通过为每只眼睛提供不同的图像,使用立体成像(3D)向不同的眼睛显示某些椭圆。我安装了DirectX SDK和SharpDX,我想使用生成的椭圆(2D),并使用NVIDIA 3D和快门眼镜以立体/3D方式显示它 给出了如何使用3D在c#中显示立体图像的答案,但它使用了曲面类。我在互联网上搜索了很多,但找不到绘制形状的方法,也找不到使用已经绘制的形状而不是图像

我目前开发了一个应用程序,它使用System.Graphics.DrawEllipse绘制了几个椭圆,在c#中效果很好

现在我想将其集成,以便通过为每只眼睛提供不同的图像,使用立体成像(3D)向不同的眼睛显示某些椭圆。我安装了DirectX SDK和SharpDX,我想使用生成的椭圆(2D),并使用NVIDIA 3D和快门眼镜以立体/3D方式显示它

给出了如何使用3D在c#中显示立体图像的答案,但它使用了曲面类。我在互联网上搜索了很多,但找不到绘制形状的方法,也找不到使用已经绘制的形状而不是图像(位图)的方法

感谢您的帮助。
谢谢。

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);

}
private byte[]getBitmapRawBytes(位图bmp)
{
矩形rect=新矩形(0,0,bmp.Width,bmp.Height);
System.Drawing.Imaging.BitmapData bmpData=
bmp.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadWrite,PixelFormat.Format32bppArgb);
//获取第一行的地址。
IntPtr ptr=bmpData.Scan0;
//声明一个数组以保存位图的字节。
int bytes=Math.Abs(bmpData.Stride)*bmp.Height;
字节[]rgbValues=新字节[字节];
//将RGB值复制到数组中。
System.Runtime.InteropServices.Marshal.Copy(ptr,rgbvalue,0,字节);
//解锁位。
bmp.UnlockBits(bmpData);
返回RGB值;
}
/// 
///位图和纹理的大小应该相同。
///纹理格式应为B8G8R8A8_UNorm
///位图pixelformat读取为pixelformat.Format32bppArgb,因此如果这是本机格式,速度可能更高?
/// 
/// 
/// 
public void writebitmapottexture(位图bmp、GPUTexture tex)
{
System.Diagnostics.Debug.Assert(tex.Resource.Description.Format==Format.B8G8R8A8_UNorm);
var bytes=getBitmapRawBytes(bmp);
tex.SetTextureRawData(字节);
}

我的工作方式是将创建的每个椭圆(通过图形)保存在位图中,将每个位图添加到位图列表中,并将这些位图加载到Direct3D曲面列表中,然后通过索引访问我想要的曲面


我希望它也能帮助其他人。

系统。绘图是GDI。它不是DirectX,也不与兼容。您将无法使用
System.Drawing
类来执行任何与DirectX相关的操作。如果您想保持简单,最好使用DirectX11.1和Direct2D。使用DX11.1,设置一个。Direct2D还提供类似GDI的方法,如绘制/填充椭圆。这两种API都由SharpDX提供。