本文主要是介绍WPF中,如何使用图像API进行绘制而不是XAML?——出自《IT168》,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先,由于WPF中不象GDI+中有Graphics对象,因此你无法使用Graphics进行绘图了,取而代之的是:DrawingContext;类似地,GDI+中的OnPaint已被OnRender取代。其次,UIElement有一个OnRendar方法,它的定义是:
但我们不能直接调用OnRender方法,也不能直接创建DrawingContext实例,但可以利用 DrawingGroup.Open 和DrawingVisual.RenderOpen。
这里举两个例子:
(1)自定义绘制Canvas:
2)保存图片到文件:
最后附上这里的一段话(http://blogs.msdn.com/timothyc/archive/2006/06/16/634638.aspx),除加重点文字以桔色示凸出外, 以原样提供:
Adding seemingly simple tweaks (e.g., clipping, bitmap effects) to our scene causes us to fall back to software, and software rending in WPF is slower than GDI+ software rendering.
First, the WPF software rendering code is derived from the GDI+ codebase. There are certain limits to what can be accomplished in hardware, and we have to work around what the hardware vendors give us. As graphics hardware evolves, those limits are likely to become better over time. If at least some portion of your scene is rendered in hardware, the cost of rendering is already going to be faster than it was in GDI+. Finally, we shipped a tool at the PDC called ‘Perforator’ to help identify where software rendering occurs.
(注意桔色文字部分)
这篇关于WPF中,如何使用图像API进行绘制而不是XAML?——出自《IT168》的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!