在 WP7 中创建用于后台渲染的图形设备



是否可以创建一个单独的图形设备用于WP7中的背景渲染?

我尝试做的是偶尔使用 XNA 渲染图像并在 silverlight 应用程序中使用它。目前,我能够使用SharedGraphicsDeviceManager来实现这一点,它可以访问当前的GraphicDevice。缺点是我被迫为每个图像打开和关闭共享模式(SetSharingMode) - 这确实需要一些时间(100-200 毫秒)。我宁愿为此使用单独的设备。

另一种选择是对整个页面使用纯 XNA 渲染模式,但这给手机带来了不必要的压力,因为它每秒渲染大部分静态图像 30 次。

任何想法将不胜感激。

将图像绑定到页面背景怎么样?

<Grid x:Name="LayoutRoot" Background="{Binding BackgroundImage}">
    <!-- other content for the page -->
</Grid>

然后,您可以随时在 ViewModel 的代码隐藏中更改图像

public class ViewModel
{
    private ImageBrush _backgroundImage;
    public ImageBrush BackgroundImage
    {
        get { return _backgroundImage; }
        set
        {
            _backgroundImage = value;
            OnPropertyChanged("BackgroundImage");
        }
    }
    // pass the uri of the newly saved image. Even if it's the same location
    // firing the PropertyChanged event will make the page get the new image
    public void ChangeImage(Uri newImageLocation)
    {
        BitmapImage source = new BitmapImage(newImageLocation);
        BackgroundImage = new ImageBrush { ImageSource = source}; 
    }
}

最新更新