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?
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
.
System.IO.FileStream stream = new System.IO.FileStream(@"C:\Images\Box.png", System.IO.FileMode.Open);
Texture2D texture = Texture2D.FromStream(GraphicsDevice, stream);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With