简体   繁体   中英

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. 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[] :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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