Advertisement
smc_gamer

LoadFromFile

Jan 24th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. public static Texture2D LoadFromFile(string filePath)
  2. {
  3. if (!filePath.EndsWith(".png")) { throw new ArgumentException("Tried to load an image that was not a PNG.", "filePath"); }
  4. if (!File.Exists(filePath)) { throw new FileNotFoundException(string.Format("The file at {0} does not exist.")); }
  5.  
  6. using (Stream stream = File.OpenRead(filePath))
  7. {
  8. return Texture2D.FromStream(GameServices.Graphics, stream);
  9. }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement