我尝试将byte
数组转换为图像,但没有任何错误。
byte[] data = user.Properties["thumbnailPhoto"].Value as byte[];
if (data != null)
{
using (MemoryStream s = new MemoryStream(data))
{
Bitmap bmp = new Bitmap(s);
imbThumbnail.ImageUrl = bmp.ToString();
}
}
答案 0 :(得分:1)
您不需要Bitmap
课程。您只需要base64编码数据,如下所示
imbThumbnail.ImageUrl = "data:image/jpeg;base64,"+ Convert.ToBase64String(data);
答案 1 :(得分:0)
试试这个。
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
来源:C# Image to Byte Array and Byte Array to Image Converter Class
答案 2 :(得分:0)
试试这段代码:
var stream = new MemoryStream(bytes);
var image = Image.FromStream(stream);