public byte[] ImageToByte(string imgUrl)
{
try
{
byte[] imageBytes = client.DownloadData(imgUrl);
return imageBytes;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
因此,我已经使用这段代码将图像下载为位数组,并将它们添加到数据库中。我想知道如何将字节数组变回图像。
尝试一下:
using (var ms = new MemoryStream(byteArray))
{
return Image.FromStream(ms);
}