DrawImage / DrawLine using XNA / DirectX
i'm building a song visualization where i need to compute each ~50ms a new Bitmap and show this on the Form by painting it on a picturebox.
Unfortunately the rendering / painting performa开发者_如何学Gonce of this image isn't fast when using DrawImage / DrawLine.
Is there a way to improve by using XNA / DirectX?
Which one is better for this task?
Any examples?
XNA uses DirectX in the Background. Also you can't directly use plain DirectX in C# anymore, because ManagedDX was discontinued because of XNA. There are alternatives though slimdx for example. XNA is closer to an engine that uses directx. What you need is a more low level approach, where it seems that the drawing performance is not the real issue, but the managed memory io operations. I would suggest to use Direct2D(also part of slimdx), which uses hardware acceleration and is more suitable for 2D rendering. You could also try this and manipulate the bitmap completely by hand.
I'd agree with using xna in a manner similar to the winforms sample.
I think you might get the best appearance and performance for the lines not by rendering a bitmap or using the SpriteBatch but by creating a dynamic vertex buffer to contain all the endpoints of all the lines. Then use the DrawUserPrimitives() and specify the primitiveType param to be PrimitiveType.LineList.
This sends all those points to the GPU where you can create all kinds of effects (shaders) on the lines while the GPU does all the heavy lifting.
Some of the samples in the educational section of the app hub use this kind of rendering to make grids. One that comes to mind is the perPixelLighting sample. You may (or may not) need to to work somewhat in 3d space.
精彩评论