WPF中表现最佳的班级 [英] Best performing class for Drawing in WPF

查看:64
本文介绍了WPF中表现最佳的班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

改善Canvas性能

在我的wpf应用程序中,我将图像加载为位图并在我的控件上绘制它作为背景。
在此图片上,我想绘制一些几何形状,例如椭圆。
因此,我必须在此控件中接收mouseclick和mousemove事件,才能知道在哪里绘制几何图形。

in my wpf application I load a image as bitmap and draw it as a background on my control. On this picture I want to draw some geometries, for example ellipses. So i have to recieve mouseclick and mousemove events in this control for knowing where to draw my geometry.

实际上,我是从画布派生我的控件类的类,但我全屏播放这很慢。
如果我是从控件类派生的,则只能接收所有已绘制图像或几何图形上的鼠标事件。

Actually I derive my control class from the "canvas" class, but i fullscreen this is to slow. And if I derive from the "control" class, only mouse events on allready drawn images or geometries can be recieved.

所以问题是:什么是在WPF中派生出的最好的类,用于绘制具有最佳性能的几何图形,以及总是会发生鼠标事件的地方?

So the Question is: What is the best class to derive from in WPF for drawing some geometries with the best performance and where alway mouse events can occure?

谢谢:)

推荐答案

对于WPF,可以使用DrawingVisual实现最佳性能的绘图。这些是一次性创建的类,其中包含要在屏幕上呈现的特定几何图形。这比重写OnRender更好,因为OnRender事件基本上每次刷新都会重新创建整个控件,而只有更改的对象需要使用DrawingVisual进行更新。

For WPF the best performing drawing can be achieved using DrawingVisual. These are one-time created classes that hold a specific geometry to be rendered on the screen. This is better than overriding OnRender as the OnRender event basically recreates your entire control each refresh whereas only objects that change need to be updated using DrawingVisual

如果您仍然需要更高的性能,请尝试 WriteableBitmapEx ,这是Silverlight& WPF库,可直接绘制到位图上。它的速度非常快,但不会提供您在WPF渲染中习惯的所有功能。

If you still need more performance try WriteableBitmapEx, this is a silverlight & WPF library for drawing directly onto a bitmap. Its blazingly fast but won't give all the features that you will be accustomed to in WPF rendering.

这篇关于WPF中表现最佳的班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆