我正在尝试在一个纹理上绘制许多纹理来为 RTS 游戏创建地图,虽然我可以在屏幕上绘制单个纹理,但将它们全部绘制到渲染目标似乎没有效果(调试时窗口仍然是 AliceBlue ) . 我试图确定是否有任何东西被绘制到渲染目标,所以我试图将它作为 Jpeg 保存到文件中,然后从我的桌面查看该 Jpeg。如何从 MemoryStream 访问该 Jpeg?
受保护的覆盖 void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
gridImage = new RenderTarget2D(GraphicsDevice, 1000, 1000);
GraphicsDevice.SetRenderTarget(gridImage);
GraphicsDevice.Clear(Color.AliceBlue);
spriteBatch.Begin();
foreach (tile t in grid.tiles)
{
Texture2D dirt = Content.Load<Texture2D>(t.texture);
spriteBatch.Draw(dirt, t.getVector2(), Color.White);
}
test = Content.Load<Texture2D>("dirt");
GraphicsDevice.SetRenderTarget(null);
MemoryStream memoryStream = new MemoryStream();
gridImage.SaveAsJpeg(memoryStream, gridImage.Width, gridImage.Height); //Or SaveAsPng( memoryStream, texture.Width, texture.Height )
// rt.Dispose();
spriteBatch.End();
}