我使用System.Drawing.Imaging从图像目录中提取图像标记。我可以很好地拉动标签,但问题是从PropertyItem发出的字符串是空终止但是我将它与之比较的字符串不是。我的问题是,如何将空终止字符串与C#中的非空终止字符串进行比较?
以下是我正在运行的代码
byte[] tagBytes = new byte[tag.Length * sizeof(char)];
System.Buffer.BlockCopy(tag.ToCharArray(), 0, tagBytes, 0, tagBytes.Length);
pnl_slider.Visible = false;
string relativePath = ConfigurationManager.AppSettings["PhotoPathRelative"];
DirectoryInfo info = new DirectoryInfo(ConfigurationManager.AppSettings["PhotoPathPhysical"]);
FileInfo[] Files = info.GetFiles("*.jpg").OrderBy(p => p.CreationTime).ToArray();
foreach (FileInfo file in Files)
{
System.Drawing.Image img = new Bitmap(file.FullName);
foreach (PropertyItem item in img.PropertyItems)
{
if (item.Id == 40094)
{
str += "'" + Encoding.Unicode.GetString(item.Value).Trim() + "' " + BitConverter.ToString(item.Value) + " == " + BitConverter.ToString(tagBytes) + "<br/>";
}
}
img.Dispose();
}
&#39; str&#39;的输出看起来像这样:
'wildlife' 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00-00-00 == 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00
'wildlife' 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00-00-00 == 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00
'wildlife' 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00-00-00 == 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00
'macro' 6D-00-61-00-63-00-72-00-6F-00-00-00 == 77-00-69-00-6C-00-64-00-6C-00-69-00-66-00-65-00
答案 0 :(得分:0)