I've decided to start work on that program I we discussed earlier that outputs file containing information about the level. I understand all of the information in the file except for what's in the <contents> tag under the tile information. I was wondering if you could tell me what is in there. My guess is that it's the image data, but I haven't ever dealt with raw image data before, so I'm not sure.
You're right, it is image data. I don't remember the format exactly, off the top of my head. I'll check when I get home. But if you don't see a second post from me within the next day or so, post something else here, and it will send me another email and remind me.
I'm pretty sure, though, that it is just a pile of bytes. The image's width and height measured in pixels, is probably first, though it might be height then width. Then it is the red, green, blue, and alpha values for each pixel. Each color is 1 byte. So each pixel is 4 bytes.
Tell you what: when I get home, I'll grab my code for loading this in and post it here so you can see how I've loaded it in the program.
Of course, depending on what your utility program is trying to accomplish, you may be able to just skip over it, or simply maintain the pile of bytes (as a string) at leave it at that. If you're not actually trying to load the image, you can probably get away with that.
Also, I think I might have just remembered that I'm storing the image width and height as an attribute to one of those XML nodes, so the width and height may not be in that contents node.
Hmm… all of this will be clearer later, when I get a chance to post that part of the code. Like I said, remind me if you don' t see anything in the next day or so.
I'll let you figure out where to go from here, but the code I'm using to load this all in in Realm Factory is this:
int height = Convert.ToInt32(tileNode.Attributes["height"].Value); int width = Convert.ToInt32(tileNode.Attributes["width"].Value); Bitmap image = new Bitmap(width, height); foreach (XmlNode childNode in tileNode.ChildNodes) { if (childNode.Name == "contents") { byte[] binaryData = Convert.FromBase64String(childNode.InnerText); for (int row = 0; row < height; row++) { for (int column = 0; column < width; column++) { byte red = binaryData[(column + row * image.Width) * 4 + 0]; byte green = binaryData[(column + row * image.Width) * 4 + 1]; byte blue = binaryData[(column + row * image.Width) * 4 + 2]; byte alpha = binaryData[(column + row * image.Width) * 4 + 3]; System.Drawing.Color color = System.Drawing.Color.FromArgb(alpha, red, green, blue); image.SetPixel(column, row, color); } } } }
This is using WinForms, which I think is where the Bitmap class is actually coming from, and it is using the System.Xml stuff, which is where the XmlNode class is at. There's more than one way to handle XML files, so you may be doing it a different way, but that's the code I've got, at any rate.
Thanks. However I end up doing it, this will be helpful.