【问题标题】:How to change the size of a Writeablebitmap?如何更改 Writeablebitmap 的大小?
【发布时间】:2014-03-15 02:54:25
【问题描述】:

我正在尝试将我的 XNA 游戏嵌入到我的 WPF 应用程序中。

为此,我获取了 XNA 游戏的屏幕像素,然后将其复制到 WriteableBitmap 上,这样:

 em_renderTarget2D.GetData(em_bytes);
 WriteableBitmap.Lock();
 System.Runtime.InteropServices.Marshal.Copy(em_bytes, 0, WriteableBitmap.BackBuffer, em_bytes.Length);
 WriteableBitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, em_sizeViewport.X, em_sizeViewport.Y));
 WriteableBitmap.Unlock();

然后我在我的 WPF 应用程序上获取位图并显示它。

问题是,我希望能够在游戏运行时调整位图的大小(例如,当客户端调整应用程序的大小时)。

所以我重新定义了 m_bytes、rendertarget ......然后我创建了一个新的 writeablebitmap:

WriteableBitmap = new WriteableBitmap(em_sizeViewport.X, em_sizeViewport.Y, 96, 96, PixelFormats.Bgr565, null);

问题是,当我调整我的应用程序大小时,图像变成全黑... 问题可能来自哪里? 即使新的宽度和新的高度和以前一样,图像也是黑色的。

【问题讨论】:

    标签: c# wpf xna


    【解决方案1】:

    看图书馆http://writeablebitmapex.codeplex.com/

    var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 2012-05-03
      • 2019-03-18
      • 2019-06-11
      相关资源
      最近更新 更多