问题
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