開發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