如何从用户的计算机加载图像 [英] How to load Image from user's computer
本文介绍了如何从用户的计算机加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从用户计算机将图像加载到XNA游戏?例如,我想加载C:\Images\Box.png来实现sprite纹理。可能吗?如果是,怎么做?
Is it possible to load image to XNA game from user computer? For example, I want to load "C:\Images\Box.png" to sprite texture. Is it possible? If yes, how?
推荐答案
在XNA 4.0中使用 Texture2D.FromStream
In XNA 4.0 use Texture2D.FromStream
Texture2D fileTexture;
using(FileStream fileStream = new FileStream(@"C:\Images\Box.png", FileMode.Open))
{
fileTexture = Texture2D.FromStream(GraphicsDevice, fileStream);
}
如果您正在使用4.0之前的XNA然后你可以使用 Texture2D.FromFile
。
这篇关于如何从用户的计算机加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文