简体   繁体   中英

Loading .bmp into Texture2D

I need to load a .bmp file into a Texture2D. To do this, I am using

 blank =   Content.Load<Texture2D("C:\\Users\\Moray\\Desktop\\TP6\\GameMap\\GameMap\\GameMapContent\\blank");

First, while the command executes, there is an error saying that the file cannot be opened.

Second, I am using the full path of the image and that won't work on other computers. The reason I do so, is that when I use Content.RootDirectory + "\\\\map.bmp" , it says that the file could not be found.

What can I do to solve these issues?

无需放置扩展名,仅需放置Content.LoadTexture2D(“ nameOfYourFile_Without_The_Extension”);

Did you import the image on the project using Visual Studio? At the right you have

'NameOfYourProject[Content]'. Click on it, then 'add an existing element', browse your file and put it.

Second, when you use Content.Load<Texture2D>("path/to/my/file") you are browsing your ProjectContent, you don't put the full path, and you don't put the file extension, XNA will not understand if you do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM