0

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.

Su Llewellyn
  • 2,660
  • 2
  • 19
  • 33
  • Assuming you are using `System.Drawing.Bitmap`, a lot of the info you want is available as properties on that object: https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.7.2 – zaitsman Dec 18 '18 at 00:08
  • I should have started at Microsoft Docs! Thank you, sir. And the native pixel formats I found there is at the link : https://learn.microsoft.com/en-us/windows/desktop.wic/-wic-codec-native-pixel-formats – Su Llewellyn Dec 18 '18 at 00:11
  • Can you use the Answer functionality so I can marks your comment as the answer? – Su Llewellyn Dec 18 '18 at 00:12

1 Answers1

1

Assuming you are using System.Drawing.Bitmap, a lot of the info you want is available as properties on that object: https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.7.2, for example:

  • Size
  • PhysicalDimension
  • Flags (this contains info about alpha channel)
zaitsman
  • 8,984
  • 6
  • 47
  • 79