I’m trying to embed a Texture2D into a .DLL, then load it from the assembly, but I’ve been having some problems. I suspect that I’m going about this horribly wrong. Here’s some of the code:
First, I generate a file like this:
Texture2D write = Content.Load< Texture2D >(“font 12”);
StreamWriter writer = new StreamWriter(“font 12”);
byte array = new byte[write.Height * write.Width];
write.GetData< byte >(array);
for (int i = 0; i < array.Length; i++)
{
writer.Write(array[i]);
}
writer.Dispose();
The idea being that I’m writing a byte array to a file from the Texture2D data.
Then I add the generated file to the DLL project as an embedded file. When it’s time to load the file, I use this code:
Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(“GUI.font 12”);
Texture2D Font = new Texture2D(device, 430, 12);
List< byte > data = new List< byte >();
for (int i = 0; i < stream.Length; i++)
{
data.Add((byte)stream.ReadByte());
}
Font.SetData< byte >(data.ToArray());
stream.Dispose();
Then the project I’m using the .DLL in builds, but it doesn’t display properly. The line
Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(“GUI.font 12”);
might be part of the problem, since I honestly have no idea what Type to pass to GetAssembly(). “This” is just a class from my .DLL.
Am I doing this horribly wrong? My other idea was to embed the .xnb file itself in the .DLL and then generate it when the .DLL is used, but I ran into different troubles there.