Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load Image from user's computer

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?

like image 929
user35443 Avatar asked Nov 03 '11 15:11

user35443


2 Answers

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.

like image 193
George Duckett Avatar answered Oct 21 '22 05:10

George Duckett


System.IO.FileStream stream = new System.IO.FileStream(@"C:\Images\Box.png", System.IO.FileMode.Open);
Texture2D texture = Texture2D.FromStream(GraphicsDevice, stream);
like image 33
neeKo Avatar answered Oct 21 '22 07:10

neeKo