0

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

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

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

任何想法,将不胜感激。

4

1 回答 1

0

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

<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}; 
    }
}
于 2012-05-27T20:33:41.627 回答