我想用一个Texture2D作为system.drawing.bitmap [英] I want to use a Texture2d as a system.drawing.bitmap

查看:1251
本文介绍了我想用一个Texture2D作为system.drawing.bitmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XNA.Texture2D到System.Drawing.Bitmap 我相信这回答我的问题,但它链接外部网站,并不再可用。

XNA.Texture2D to System.Drawing.Bitmap I am sure this answered my question but it linked an external site and is no longer available.

我在XNA游戏使用Windows窗体。我想用一个背景图片为我的面板之一。这是很容易从文件做装载,但是当比赛被部署到另一个系统显然该文件的位置会有所不同。

I am using a windows form in an xna game. I want to use a background image for one of my panels. It is easy enough to do the loading from file, but when the game is deployed to another system obviously the file location will be different.

Bitmap bmp = new Bitmap(@"c:\myImage.png");

在上面提到的问题,有人曾建议usign Texture2d.saveToPng然后从内存流打开位图。这听起来很不错,如果有人可以引导我在那个方向。任何其他的想法?

In the above mentioned question, someone had suggested usign Texture2d.saveToPng then open the bitmap from the memory stream. This sounds great, if someone could steer me in that direction. Any other ideas?

推荐答案

您可以使用两种方法,使您可以创建一个位图,使用的Texture2D .SaveAsJpeg() Texture2D.SaveAsPng()

You can use two methods that allow you to create a Bitmap, use Texture2D.SaveAsJpeg() or Texture2D.SaveAsPng().

MemoryStream memoryStream = new MemoryStream();
Texture2D texture = Content.Load<Texture2D>( "Images\\test" );
texture.SaveAsJpeg( memoryStream, texture.Width, texture.Height ); //Or SaveAsPng( memoryStream, texture.Width, texture.Height )

System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( memoryStream );

这篇关于我想用一个Texture2D作为system.drawing.bitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆