I want to save a loaded Texture2D in .xnb format, how can i do it ?
Thanks !
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Does that Work?
Hm, I don’t think you can do that the way you want to. The reason is that the XNB file is created outside of the game runtime. The ContentManager is just a way of loading/deserializing this data. This can be seen in this diagram of the XNA content pipeline’s architecture.
So What Should You Do?
I’m guessing what you want to do is save out image information during the game and load it back in. To do that, you will need to write out the Texture2d information the same way you would save any other content in XNA. There’s great help with "Saving Data to a Save Game file" on MSDN, so I will not reiterate what they say so well.
In order to get the Texture data and write it back out, you’ll want to use the pair of Texture2D methods called Texture2D.SetData and Texture2D.GetData. I would probably just use this overload that gets an array and sets an array of color information.
Update Windows Only
App Hub has a code sample for creating XNB files on Windows that will let you do it if the computer has XNA Game Studio installed.