【问题标题】:How to convert an image to bytes to save it in a database and retrieve from database? [duplicate]如何将图像转换为字节以将其保存在数据库中并从数据库中检索? [复制]
【发布时间】:2014-11-05 12:32:30
【问题描述】:

我正在尝试将图像转换为字节以将其保存在数据库中并从数据库中检索。

我该怎么做?

【问题讨论】:

标签: c# image byte


【解决方案1】:

您可以创建一个MemoryStream,将图像保存到其中,然后使用ToArray 方法获取字节:

此代码假定您有一个名为 imageImage

byte[] bytes;
using (MemoryStream ms = new MemoryStream())
{
    image.Save(ms, ImageFormat.Png);
    bytes = ms.ToArray();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-25
    • 2011-05-18
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多