I am an SDE/T and I need to write a method that compares two images, to ensure that the image during a test meets expected results. I'd like to make an XML model of the image and just compare that XML to the expected XML model (using a fault tolerance to allow for slight differences).
I found this StackOverflow article on sending image data to XML: Link
I found this Wikipedia article on the Bitmap format: Bitmap Format
I found an article in CodePlex that allows you to make an Bitmap object into XML. But I want to encode certain image metadata.
This is the method used in the CodePlex article to export the data to XML:
public void ExportToXML(Dictionary<string, Bitmap> BmpList, string Filename)
{
XmlNode node = null;
XmlNode subnode = null;
XmlAttribute attr = null;
XmlDocument doc = new XmlDocument();
if (System.IO.File.Exists(Filename))
doc.Load(Filename);
// Select or create a Graphics root node
XmlNode root = doc.SelectSingleNode("/Graphics");
if (root == null)
{
root = doc.CreateNode(XmlNodeType.Element, "Graphics", null);
doc.AppendChild(root);
}
// If the Symbols section exists, get rid of it
node = root.SelectSingleNode("descendant::Symbols");
if (node != null)
root.RemoveChild(node);
// Create a new Symbols section
node = doc.CreateNode(XmlNodeType.Element, "Symbols", null);
root.AppendChild(node);
// Save the pattern info
foreach (string bmpName in BmpList.Keys)
{
Bitmap bmp = BmpList[bmpName];
// what about RGB and alpha channel info?
subnode = doc.CreateNode(XmlNodeType.Element, "symbol", null);
attr = doc.CreateAttribute("name");
attr.Value = bmpName;
subnode.Attributes.Append(attr);
byte[] bb = ByteArrayFromBitmap(ref bmp);
string ss = Convert.ToBase64String(bb);
attr = doc.CreateAttribute("bitmap");
attr.Value = ss;
subnode.Attributes.Append(attr);
node.AppendChild(subnode);
}
doc.Save(Filename);
}
Can someone suggest a way to get at information about bitmap images? I think it might be a more robust way to handle images in testing.
Possible metadata to encode:
- Image Name
- Image Size
- Image Date
- Alpha Channel information
- pixel format
- ICC color profile
- compression
Perhaps I can make a hash value for the Image data itself, somehow, but then I need to understand how to introduce fault tolerance into such a calculation. Any suggestions are greatly appreciated.