将字节数组变回img

问题描述 投票:0回答:1
public byte[] ImageToByte(string imgUrl)
{
    try
    {
        byte[] imageBytes = client.DownloadData(imgUrl);
        return imageBytes;
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        return null;
    }
} 

因此,我已经使用这段代码将图像下载为位数组,并将它们添加到数据库中。我想知道如何将字节数组变回图像。

c#
1个回答
1
投票

尝试一下:

using (var ms = new MemoryStream(byteArray))
{
    return Image.FromStream(ms);
}
© www.soinside.com 2019 - 2024. All rights reserved.