wpf WPF中的快速像素绘制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12582577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fast pixel drawing in WPF
提问by Gigi
I would like to write a simple ray tracer using WPF. It is a learning project and thus I favour configurability over performance (otherwise I'd go for C++).
我想使用 WPF 编写一个简单的光线追踪器。这是一个学习项目,因此我更喜欢可配置性而不是性能(否则我会选择 C++)。
I still want relatively fast pixel drawing. A previous questionon StackOverflow contains code to achieve this in WPF, by obtaining a GDI bitmap. From the relatively little I know about Windows programming,
我仍然想要相对较快的像素绘制。一个先前的问题在计算器上包含的代码在WPF来实现这一点,通过获得GDI位图。从我对 Windows 编程的了解相对较少,
- GDI is slow
- DirectX is fast
- WPF uses DirectX underneath (not sure which parts of WPF though)
- GDI 很慢
- DirectX 很快
- WPF 在下面使用 DirectX(虽然不确定 WPF 的哪些部分)
Is it possible to obtain pixel-level access using DirectX (not GDI) through the WPF Canvas (or similar)?
是否可以通过 WPF Canvas(或类似的)使用 DirectX(而不是 GDI)获得像素级访问?
I will also consider suggestions for incorporating DirectX API calls within a WPF window (alongside other WPF controls) if that is possible.
如果可能的话,我还将考虑将 DirectX API 调用合并到 WPF 窗口(与其他 WPF 控件一起)的建议。
Thanks in advance.
提前致谢。
采纳答案by Kieren Johnstone
Interesting, but with raytracing, writing the pixels to the screen will (should) not be the slow part. You can use WriteableBitmapfor the purpose, though. It's certainly quick enough for what you want.
有趣的是,但对于光线追踪,将像素写入屏幕将(应该)不是缓慢的部分。不过,您可以WriteableBitmap为此目的使用。对于您想要的东西,它当然足够快。
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx
(For info, I use it in this emu/IDE - http://0x10c-devkit.com/- and it can refresh a low res display with great performance. There's the source to that on the github repository, the LEM1802 plugin.)
(有关信息,我在这个 emu/IDE 中使用它 - http://0x10c-devkit.com/- 它可以以出色的性能刷新低分辨率显示。在 github 存储库中有源代码,LEM1802 插件。 )
Ah, this bit: https://github.com/kierenj/0x10c-DevKit/blob/master/PluginAPI/NyaElektriska.LEM1802/GPU.cs- see UpdateDisplay.
啊,这一点:https: //github.com/kierenj/0x10c-DevKit/blob/master/PluginAPI/NyaElektriska.LEM1802/GPU.cs- 见UpdateDisplay。
回答by Joel Lucsy
Another solution is WriteableBitmapEx. It extends the builtin WriteableBitmap.
另一种解决方案是WriteableBitmapEx。它扩展了内置的 WriteableBitmap。
回答by Pascalsz
There is an open Source Project Called Direct Canvas wich is A hardware accelerated, 2D drawing API that supports vector graphics, multimedia files, extensible pixel shaders, blending modes and more!
有一个名为 Direct Canvas 的开源项目,它是一个硬件加速的 2D 绘图 API,支持矢量图形、多媒体文件、可扩展像素着色器、混合模式等!
http://directcanvas.codeplex.com/
http://directcanvas.codeplex.com/

