以字节形式存储在数据库中的图像在 table 上不显示为图像,而是显示为字节
Stored image on database as bytes does not show as image on table but as bytes
我正在尝试以字节数组格式将图像保存到我的数据库中,但是当我查看数据库时,我只看到字节而看不到图像!我怎样才能使我看不到字节码但看不到图像?我是否必须在客户端撤消该过程?
请帮忙!谢谢!
字节转换函数:
private byte[] String_To_Bytes2(string strInput)
{
int numBytes = (strInput.Length) / 2;
byte[] bytes = new byte[numBytes];
for (int x = 0; x < numBytes; ++x)
{
bytes[x] = Convert.ToByte(strInput.Substring(x * 2, 2), 16);
}
return bytes;
}
我设法使用以下 post 中找到的第一个解决方案解决了问题:
Displaying database image (bytes[]) in Razor/MVC3?
Model.Content 是 byte[] 图像。
@{
string imageBase64 = Convert.ToBase64String(Model.Content);
string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);} <img src="@imageSrc" alt="@Model.Name" width="100" height="100" />
我正在尝试以字节数组格式将图像保存到我的数据库中,但是当我查看数据库时,我只看到字节而看不到图像!我怎样才能使我看不到字节码但看不到图像?我是否必须在客户端撤消该过程? 请帮忙!谢谢!
字节转换函数:
private byte[] String_To_Bytes2(string strInput)
{
int numBytes = (strInput.Length) / 2;
byte[] bytes = new byte[numBytes];
for (int x = 0; x < numBytes; ++x)
{
bytes[x] = Convert.ToByte(strInput.Substring(x * 2, 2), 16);
}
return bytes;
}
我设法使用以下 post 中找到的第一个解决方案解决了问题: Displaying database image (bytes[]) in Razor/MVC3?
Model.Content 是 byte[] 图像。
@{
string imageBase64 = Convert.ToBase64String(Model.Content);
string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);} <img src="@imageSrc" alt="@Model.Name" width="100" height="100" />