首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将System.Graphics.DrawEllipse显示/实现为DirectX 3D曲面?!c#

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

Stack Overflow用户
提问于 2013-07-30 18:50:07
回答 2查看 630关注 0票数 0

我目前已经开发了一个应用程序,它使用System.Graphics.DrawEllipse绘制几个椭圆,在c#中工作得很好。

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

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

任何帮助都是非常感谢的。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-24 10:36:24

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

我希望这对其他人也有帮助。

票数 0
EN

Stack Overflow用户

发布于 2013-08-01 08:12:56

在directx和GDI之间没有直接的交互方式。当我解决同样的问题时,我求助于准备从GDI到内存的字节,然后返回到direct3D。我在下面添加了我的代码,因为我认为它在我的项目中使用:)

注这是用于directx11 (应该很容易转换)。此外,使用*B*GRA纹理格式是有意的,否则颜色倒置。

如果您需要更多的性能,我建议您查看DirectDraw。

代码语言:javascript
复制
    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);

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17955020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档