我是 SDE/T,我需要编写一个比较两个图像的方法,以确保测试期间的图像符合预期结果。我想制作图像的 XML 模型,然后将该 XML 与预期的 XML 模型进行比较(使用容错以允许细微差异)。我发现这篇关于将图像数据发送到 XML 的 StackOverflow 文章:链接我发现这篇关于位图格式的维基百科文章:位图格式我在 CodePlex 中发现了一篇文章,它允许您将 Bitmap 对象转换为 XML。但我想编码某些图像元数据。这是 CodePlex 文章中用于将数据导出到 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); }有人可以建议一种获取有关位图图像信息的方法吗?我认为这可能是在测试中处理图像的一种更强大的方法。可能要编码的元数据:图片名称图片尺寸图片日期阿尔法通道信息像素格式ICC 颜色配置文件压缩也许我可以以某种方式为图像数据本身创建一个哈希值,但是我需要了解如何将容错引入到这样的计算中。非常感谢任何建议。
1 回答
![?](http://img1.sycdn.imooc.com/5458502c00012d4a02200220-100-100.jpg)
慕桂英546537
TA贡献1848条经验 获得超10个赞
假设您正在使用System.Drawing.Bitmap
,您想要的很多信息都可以作为该对象的属性:https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.7。 2,例如:
尺寸
物理维度
标志(这包含有关 Alpha 通道的信息)
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报
0/150
提交
取消