开发者

C# / Silverlight / WPF / Fast rendering lots of circles

I want to render a lot of circles or small graphics within either silverlight or wpf (around 1000-10000) as fast and as frequently as possible. If I have to go to DX or OGL, that's fine, but I'm wondering about doing this within either of those two frameworks first (read: it's OK if an answer is WPF-only or Silverlight-only). Also, if there is a way to access DX through WPF and render on a surface that way, I would be interested in that as well.

So, what's the fastest way to draw a load of circles? They can be as plain as necessary, but they do need to have a radius. Currently I'm using DrawingVisual and a DrawingContext.DrawEllipse() comm开发者_运维百科and for each circle, then rendering the visual to a RenderTargetBItmap, but it becomes very slow as the number of circles rises.

By the way, these circles move every frame, so caching isn't really an option unless you're going to suggest caching the individual circles . . . But their sizes are dynamic, so I'm not sure that's a great approach.


In Silverlight 3.0+, most likely, you will use WriteableBitmap for this. In WPF it also may be a good choice.

I wrote two demo applications in Silverlight. They may be little buggy, but they demonstrate the point.

  1. Hello world application. Definitely can be optimized. Performance isn't that good, but that's because I made something stupid. I believe it has ~2 500 ellipses:

alt text http://img42.imageshack.us/img42/5629/helloworld.jpg

  1. Slide show application. I can't recall number of objects here, but it's way more than 10 000.

alt text http://img11.imageshack.us/img11/5264/slideshowa.jpg


Check out the WriteableBitmapEx library for Silverlight which will surely work with WPF too. The circle functionality was introtuced in this blog post including a sample.


If you want speed do not use draw Ellipse - pre generate your circles for sizes and colours and use write bitmap and you will get full BitBlt acceleration.

This may be difficult depending on your background , transparency needs or anti aliasing but it will be orders of magnitudes faster.

Using anti aliased line drawing is slow but is ok for most thigs since it odesnt change the results can be cached and you get multiple frames with the result.

However if you want to draw as fast as possible use non transparent Bitmaps.


While you have accepted an answer already, if you find you need to use DirectX9 (inter-op with later versions is a bit harder but can still be done (depending on hardware)) you can use the D3DImage component. Which is detailed on CodeProject Here.

The other option is you can just use a host a WinForms control and use the hWnd of that for D3D device creation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜