windows phone開發學習–CacheMode

來源:互聯網
上載者:User

開發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
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.