Windows Store App:BitmapCache性能不佳 [英] Windows Store App: BitmapCache poor performance

查看:67
本文介绍了Windows Store App:BitmapCache性能不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们有一个可以在 Windows Phone 上顺利运行的应用程序,但相同的代码在
Windows 8 上显示性能不佳>。

We have an app which runs smoothly on Windows Phone but the same code shows poor performance on Windows 8.

更详细地说,我们有一个复杂的控件,完全使用
Border-s
TextBlock-s Shape-s 。用户可以缩放此控件。为了使此操作顺利进行,我们将
CacheMode 属性设置为 BitmapCache RenderTransform 属性设置为
ScaleTransform 。我们处理来自触摸或鼠标操作的用户输入,并计算适当的比例值,这些值设置为 ScaleTransform ScaleX / ScaleY 属性>。

In more detail, we have a complex control which is entirely drawn using Border-s, TextBlock-s and Shape-s. User may scale this control. To make this operation smooth we set CacheMode property to BitmapCache. RenderTransform property is set to ScaleTransform. We process user input from touch or mouse manipulations and calculate appropriate scale values which are set to the ScaleX / ScaleY properties of the ScaleTransform.

由于控件是位图缓存的,因此缩放操作会传递给GPU,程序可以在
Windows Phone 上顺利运行。但不是 Windows 8 !奇怪,呵呵?

Since the control is bitmap-cached, scale operations are passed to GPU and program runs smoothly on Windows Phone. But not on Windows 8! Strange, huh?

设置 ScaleTransform.ScaleX / ScaleTransform.ScaleY 属性非常慢,即使控件是在$上缓存位图b $ b Windows 8

Setting the ScaleTransform.ScaleX / ScaleTransform.ScaleY properties is very slow even if control is bitmap cached on Windows 8.

未将 CacheMode 属性设置为 BitmapCache 值也显示为低性能,因为每个规模变化迫使程序重新呈现控件的内容(很多
边框 TextBlocks )。

Not setting the CacheMode property to the BitmapCache value also shows low performance because each scale change forces program to rerender control’s content (lots of Borders and TextBlocks).

似乎每次控制缩放时,位图缓存在
Windows 8
上重新生成。

It seems that each time when control is scaled bitmap cache is regenerated on Windows 8.

以下是在上顺利运行的示例代码> Windows Phone 并且在
Windows 8 上显示性能不佳:

Here is sample code which runs smoothly on Windows Phone and shows poor performance on Windows 8:

XAML:

<Grid x:Name="grid" CacheMode="BitmapCache" RenderTransformOrigin="0.5,0.5">
    <Grid.RenderTransform>
        <ScaleTransform x:Name="scaleTransform"/>
    </Grid.RenderTransform>
</Grid>

C#:

// add some content to the grid
for (int i = 0; i < 100; i++)
{
    grid.Children.Add(new Border
    {
        Child = new TextBlock
        {
            Text = "Hello World"
        },
        Background = new SolidColorBrush(Colors.Red),
        Width = 10,
        Height = 10
    });
}

// simulate user input (this is NOT frame-by-frame animation!)
Observable.Interval(TimeSpan.FromMilliseconds(10))
    .ObserveOnDispatcher()
    .Subscribe(x =>
    {
        scaleTransform.ScaleX *= 1.01;
        scaleTransform.ScaleY *= 1.01;
    });

此代码甚至在 Windows 8上运行几秒后崩溃(但不会在
Windows Phone 上崩溃)。

This code even crashes after several seconds running on Windows 8 (but does not crash on Windows Phone).

如何让应用程序顺利运行?你会建议什么?

How to make the app run smoothly? What would you suggest?

推荐答案

尝试转换:http://msdn.microsoft.com/en-US/library/windows/apps/xaml / Hh452703

在你的情况下,ChildrenTransitions将有助于实现相同的动画输入效果。

Try transitions: http://msdn.microsoft.com/en-US/library/windows/apps/xaml/Hh452703

In your case ChildrenTransitions would help achieving the same animated entry effect.


这篇关于Windows Store App:BitmapCache性能不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆