How to load Image from user's computer

佐手、 提交于 2019-12-07 02:00:52

问题


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?


回答1:


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

If you're using XNA before 4.0 then you can use Texture2D.FromFile.




回答2:


System.IO.FileStream stream = new System.IO.FileStream(@"C:\Images\Box.png", System.IO.FileMode.Open);
Texture2D texture = Texture2D.FromStream(GraphicsDevice, stream);


来源:https://stackoverflow.com/questions/7997750/how-to-load-image-from-users-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!