WPF - 取代GDI/GDI+ ?

本文探讨了WPF与GDI+这两种图形编程技术之间的区别及应用场景。WPF为开发者提供了更高级别的抽象和更高效的图形处理能力,尤其是在硬件加速的支持下。然而,在涉及到极其复杂的图形处理任务如3D游戏开发时,直接使用Direct3D可能是更好的选择。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看过绚烂的WPF演示后,不由提出一个问题:曾经在一些项目中使用过一点儿GDI+的东西,那的确是.NET Framework中一个稍显独立和神秘的世界,学习和掌握都需要相当时间的积累,难道WPF的出现,即宣告那些已经掌握的GDI+技能行将做古?GDI+将被WPF取代?

WPF demo picture


答案是肯定的,也是否定的。

高生产效率一直是微软技术的一贯特点,WPF是对图像编程更高层次的封装,因此可以带来更快的开发速度。使用GDI+再加上复杂的几何学知识,编写大量代码实现的效果,在WPF下面只需要简单的几行XAML代码。类似的产品,当你还在用GDI+"打地基"的时候,你的竞争对手也许已经在庆祝"封顶了" 。原因只有一个,对手使用的是WPF。此种情形下,别无选择 - 扔掉GDI+拥抱WPF吧。来自WPF Team的声音(http://blogs.msdn.com/timothyc/archive/2006/06/16/634638.aspx):

   What we’ve done with WPF is provide an entirely new set of possibilities around retained-mode graphics programming, which simply haven’t existed before.   This is a brand new class of tool, one that frees developers from thinking about pixels, painting, and vector processing.   You describe your scene using high-level constructs (or heck, even a designer tool like Microsoft Expression Interactive Designer), and we’ll worry about the rest.

[ UPDATE 2007-08-10] :另外一个可能会影响技术选择的因素 - 微软对GDI/GDI+未来的支持

[ UPDATE 2007-08-10] WPF也有弱点。由于是对Direct3D的一层managed的封装,在2D应用中其性能较之GDI/GDI+有待验证。在3D方面,其当然不如直接基于硬件的Direct3D在三维图像处理上的效率。此种情形下,原有技术可能仍是第一选择。(谁知道,也许硬件的革新会让WPF开发复杂的3D游戏也将成为现实,那层封装的开销,对于高性能硬件来说可能已经微不足道了)

[ UPDATE 2007-08-9]:关于WPF的效率问提以及于GDI/GDI+/Direct3D的比较,在评论中有些争议。这些在新技术出现的时候都无可避免。下面是关于这方面问题的一些回答,仅供参考:
1. 记得再一次.NET Club活动中,一位做WPF演示的讲着提到目前WPF不适合做复杂的3D游戏,因为在图形处理的效率的问题。
2. 同样来自上面的引用(http://blogs.msdn.com/timothyc/archive/2006/06/16/634638.aspx):

What do the remaining 1% of apps look like, who needs an immediate-mode API anyway, and how do I know if I’m in that bucket? 

 

The short answer is, applications that spend nearly all of their time rendering, such that it makes sense for them to invest in a super-performant graphics pipeline.   Graphics-intensive apps like games, CAD, or complex game-like 3D visualizations come to mind.  For these folks, Direct3D is the way to go.

3. 另外一个关于WPF,GDI+等图形处理技术选择的blog (http://www.fernicola.org/loquitor/index.php?/archives/48-What-to-use-for-fast-2D-graphics.html):

Here is the decision process I would recommend in relation to selecting between the technologies:

  • if you are doing native code (C++/COM) use GDI+ (knowing that you do not get HW acceleration (注:硬件加速))

  • if you can use managed code, try out WPF and see if its model fits what you want to do

  • if you have the expertise, time, and the value to you is worth the effort, try building a 2D layer on D3D
to 边蓬: WPF的确通过充分发掘硬件性能提高了效率 - 越来越多的图形处理都在GPU中完成 - 这也是WPF的发展趋势。但是仍然有部分功能是通过"软"实现并copy到的显卡上的. 那么软实现意味着什么呢?- 当然是CPU的工作 :-)

see here (
http://blogs.msdn.com/timothyc/archive/2006/06/16/634638.aspx ):

Some WPF features, such as gradients, must be rendered in software and then copied into texture memory on the video card.  With many Windows applications running, doesn’t this create a new class of bottlenecks around copying textures to the video card?

 

Ever since our first public preview, fewer and fewer features are being rendered in software.  That’s a trend I expect to continue.  For example, only a very small portion a linear gradient is rendered by the CPU.  Most of the pixels contained within a linear gradient are calculated by the GPU (for tier-2 cards, radial gradients are also done on the GPU).  In addition, compact WPF vectors are a new option for content which has been traditionally rendered using bitmaps.  The result will be applications which use fewer bitmaps, and thus less video memory, in favor of scalable vector graphics.

 

Finally, with Vista , the WDDM gives us virtualized video memory.   This helps make sure the most important textures are kept in video memory via an efficient memory eviction mechanism -- something we’ve never had before.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值