【问题标题】:Create a GraphicDevice for background rendering in WP7在 WP7 中创建用于背景渲染的图形设备
【发布时间】:2012-05-27 15:19:45
【问题描述】:

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

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

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

任何想法都将不胜感激。

【问题讨论】:

    标签: windows-phone-7 xna


    【解决方案1】:

    把图片绑定到页面背景怎么样?

    <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}; 
        }
    }
    

    【讨论】:

    • 感谢您的回答,但您能重新阅读问题吗?问题是没有让图像在 UI 中显示 - 它是如何使用 GraphicDevice 而不使用共享模式来呈现图像。
    猜你喜欢
    • 2020-08-20
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 2017-06-01
    相关资源
    最近更新 更多