现在的位置: 首页 > 综合 > 正文

windows phone开发学习–CacheMode

2012年01月07日 ⁄ 综合 ⁄ 共 1954字 ⁄ 字号 评论关闭

开发windows phone 8应用程序时,有时候页面上需要加载很多图从而变得很卡,解决方法就是使用GPU进行加速,不过SDK已经给开发者提供好了接口,只需要在xaml文件中图片标签处写上 

CacheMode="BitmapCache"

例如下面这个例子:

<phone:PanoramaItem Header="item5">
                <Image CacheMode="BitmapCache">

                    <Image.Source>

                        <BitmapImage UriSource="/Assets/4.png" CreateOptions="BackgroundCreation"/>

                    </Image.Source>

                </Image>
            </phone:PanoramaItem>

改写过以后,感觉界面就不那么卡了。在网上,有一段微软开发者给出的解释说明:原文在这里

Hi Andy,

     Response from our development team:

Whether everything is rendered by the GPU or not is not directly related to whether CacheMode is useful.  Most WPF applications
render everything on the GPU as well, and CacheMode can be exceptionally useful there when used judiciously.  The CacheMode API allows developers to collapse costly parts of the scene into a texture.  This incurs some upfront cost, sometimes more CPU and/or
GPU time than it would normally take to render that scene directly to the screen, and some persistent memory cost associated with storing the realized content.  The trade-off is that rendering that content subsequently is much improved – it becomes effectively
as cheap as rendering a single image, no matter how complex the UIElement tree.  This can be important beyond computation time as well.  On lower-end devices with limited GPU bandwidth, collapsing a scene with lots of overlapping content into a single image
reduces overdraw and bandwidth, which can ultimately improve the frame-rate.

Some other points worth mentioning:
• There are no limitations as there are in Silverlight 5 regarding needing to cache a UIElement in order to have animations targeting it run independently.  There are, however, some related new limitations – animations inside a cached part of the element tree
are disabled by default.

• It’s important to stress that this API should be used carefully.  Sprinkling CacheMode all over an application can often reduce run-time performance and greatly increase memory usage (especially if the content is frequently updated, which is one of the driving
motivations behind animations inside a cached tree being disabled).  It’s best to profile to determine which targeted areas are most expensive to render, and to experiment with caching based on those results.


Matt Small - Microsoft Escalation Engineer - Forum Moderator

抱歉!评论已关闭.