Using A FileStream As A Texture?
-
I'm still learning C# and I have a long way to go. I wanted to dive into MonoGame because tinkering with game design has been a hobby of mine since I started learning QBasic at the age of 14. I don't want to use their Content Pipeline to load content, because I'd like to figure out how to load custom resources as needed. Someone on Stack Overflow commented HERE that they use FileStreams to load textures directly. I set about trying to figure out how to do that, and I've gotten this far:
FileStream fs = new FileStream("stars.jpg", FileMode.Open);
byte[] readString = new byte[fs.Length];
fs.Read(readString, 0, (int)fs.Length);I have no idea if that code even works, because I haven't gotten to a point where running it would yield any visible results. It seems sound, so once I get the file data in the readString array, I need a way to use it as texture data. I tried casting:
object o = (object)readString;
background = (Texture2D)o;I already know that isn't going to work. I don't even need to run it to figure that one out. I read a little in the MonoGame Reference and thought about using Texture2D.SetData as shown HERE, but I'm not sure how to proceed or even if I'm headed in the right direction. The syntax they provide doesn't really clarify anything.
public void SetData(
T[] data
) where T : ValueType, new()There's an array here, but I'm not sure what it's asking for. Can I provide SetData with the byte array?
background.SetData(readString);
Your help would be most appreciated, and it would go a long way towards helping me advance in my learning. Thanks. :) -Turtle
-
I'm still learning C# and I have a long way to go. I wanted to dive into MonoGame because tinkering with game design has been a hobby of mine since I started learning QBasic at the age of 14. I don't want to use their Content Pipeline to load content, because I'd like to figure out how to load custom resources as needed. Someone on Stack Overflow commented HERE that they use FileStreams to load textures directly. I set about trying to figure out how to do that, and I've gotten this far:
FileStream fs = new FileStream("stars.jpg", FileMode.Open);
byte[] readString = new byte[fs.Length];
fs.Read(readString, 0, (int)fs.Length);I have no idea if that code even works, because I haven't gotten to a point where running it would yield any visible results. It seems sound, so once I get the file data in the readString array, I need a way to use it as texture data. I tried casting:
object o = (object)readString;
background = (Texture2D)o;I already know that isn't going to work. I don't even need to run it to figure that one out. I read a little in the MonoGame Reference and thought about using Texture2D.SetData as shown HERE, but I'm not sure how to proceed or even if I'm headed in the right direction. The syntax they provide doesn't really clarify anything.
public void SetData(
T[] data
) where T : ValueType, new()There's an array here, but I'm not sure what it's asking for. Can I provide SetData with the byte array?
background.SetData(readString);
Your help would be most appreciated, and it would go a long way towards helping me advance in my learning. Thanks. :) -Turtle