简体   繁体   English

读取和输出图像BLOB内容C#

[英]Reading and outputting image BLOB content C#

Well, I've searched in numerous places and I cannot find a solution. 好吧,我已经搜索了很多地方,但找不到解决方案。 I have a method that contains blob content that has been retrieved from my database. 我有一个包含从数据库中检索到的Blob内容的方法。 My problem is that I don't know how I can use the content so that it's displayed in a picture box. 我的问题是我不知道如何使用内容,以便将其显示在图片框中。 The first thing I'm assuming now is that the method must return a byte (which is why I converted it) and then it must be used somehow. 我现在假设的第一件事是该方法必须返回一个字节(这就是我对其进行转换的原因),然后必须以某种方式使用它。

    public byte getAvatar()
    {   // row content from database
        DataRow row = dt.Rows[0];
        return Convert.ToByte( row["avatar_blob"] );
    }

Past this point, I'm not sure what to do. 到目前为止,我不确定该怎么办。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Create a Bitmap from the byte[] : byte[]创建一个Bitmap

using (MemoryStream ms = new MemoryStream(yourBytes))
{
    var bitmap = new Bitmap(ms);
    yourPicturebox.Image = bitmap;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM