我有一个 Winforms 应用程序,它可以将图像作为Image
SQL Server 列的数据类型上传到 SQL Server 2005,其中包含两种方法Single
和Multiple
.
使用单个我将参数从 C# 发送到 SP 作为二进制图像。
但是有多个我需要将它们作为 XML 纯文本发送到数据库,并使用 SP 将它们转换为图像
convert(image, @myimageFromXML, 2)
我尝试了其他网站的许多功能,例如
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
public static string ByteArrayToString(byte[] ba)
{
string hex = BitConverter.ToString(ba);
return hex.Replace("-", "");
}
public static string ByteArrayToString(byte[] Bytes)
{
char[] hexes = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char[] Result = new char[Bytes.Length << 1];
int Offset = 0;
for (int i = 0; i != Bytes.Length; i++)
{
Result[Offset++] = hexes[Bytes[i] >> 4];
Result[Offset++] = hexes[Bytes[i] & 0x0F];
}
return new string(Result);
}
public static String ByteArrayToString(byte[] Source)
{
return "0x" + BitConverter.ToString(Source).Replace("-", "");
}
public static string ByteArrayToString(byte[] barray)
{
char[] c = new char[barray.Length * 2];
byte b;
for (int i = 0; i < barray.Length; ++i)
{
b = ((byte)(barray[i] >> 4));
c[i * 2] = (char)(b > 9 ? b + 0x37 : b + 0x30);
b = ((byte)(barray[i] & 0xF));
c[i * 2 + 1] = (char)(b > 9 ? b + 0x37 : b + 0x30);
}
return new string(c);
}
但他们每个人都返回不正确的数据,我无法显示它们,因为它不能呈现为图像
我在单个文档上传中保存的二进制图像中的正确图像以
0x49492A008C040600803FA04FF004160D0784..........
但是多次上传保存的错误数据以
0x310033003700380030003700380037.............
请帮助我找到如何从 C# byte[] 获取正确的二进制数据,以便将它们作为 XML 作为文本发送到 SQL Server