【发布时间】:2012-05-28 17:05:03
【问题描述】:
我需要一些帮助将十六进制字符串转换为图像
做了一些研究,我想出了这个代码:
private byte[] HexString2Bytes(string hexString)
{
int bytesCount = (hexString.Length) / 2;
byte[] bytes = new byte[bytesCount];
for (int x = 0; x < bytesCount; ++x)
{
bytes[x] = Convert.ToByte(hexString.Substring(x*2, 2),16);
}
return bytes;
}
public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
try
{
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
_FileStream.Close();
return true;
}
catch (Exception _Exception)
{
MessageBox.Show(_Exception.Message);
}
return false;
}
问题是生成的图像几乎全是黑色的,我想我需要应用一些过滤器来更好地转换灰度(因为原始图像只有灰度)
谁能帮帮我?
非常感谢
【问题讨论】:
-
等待 - 生成的二进制文件是否正常?我的意思是,您是否发现您发布的功能有任何问题?
-
但是您展示的方法只是将字符串转换为字节数组。您接下来做了什么来创建图像? Marshal.Copy?