我想以这种方式检索图像,但它不会

时间:2015-02-08 06:01:19

标签: c# mysql database image

我无法从数据库中检索图像

byte[] image = (byte[])(reader["Can_Pic"]);
if (image == null)
{
    Picture.Image = null;
}
else
{
    Memory Stream stream = new Memory Stream(image);
    Picture.Image = System.Drawing.Image.From Stream(stream);
}

1 个答案:

答案 0 :(得分:0)

您的代码应该是这样的:-)

 Byte[] image=(Byte[])(reader["Can_Pic"]); 

    if (image.Length == 0)
    {
        Picture.Image = null;
    }
    else
    {
        MemoryStream stream = new MemoryStream();
        stream.Write(image, 0, image.Length);
        Picture.Image = new Bitmap(stream);
    }