1

我想使用实体框架从 SQL Server(数据库)中检索图像并将其设置为 PictureBox 图像属性我已经创建了一个用户控件并将其继承给 PictureBox(名称:DisplayImage)

    public static void LoadDisplay(Guid? DisplayID, string Name, byte[] image)
    {
        DisplayImage objDisplayImage = new DisplayImage();
        DisplayList.Add(objDisplayImage);
        objDisplayImage.Name = Name;
        MemoryStream ms = new MemoryStream(image);
        Image myImage = Image.FromStream(ms);
        objDisplayImage.Image = myImage;
        objDisplayImage.DisplayID = DisplayID;
        PlayerForm.Instance.Controls.Add(objDisplayImage);
    }

但图片没有加载到图片框

4

1 回答 1

1

试试这个代码

try
{
    // get image from object
    byte[] _ImageData = new byte[0];
    _ImageData = (byte[])_SqlRetVal;
    System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream(_ImageData);
    _Image = System.Drawing.Image.FromStream(_MemoryStream);
}
catch (Exception _Exception)
{
    // Error occurred while trying to create image
    // send error message to console (change below line to customize error handling)
    Console.WriteLine(_Exception.Message);

    return null;
}
于 2013-03-26T09:11:19.280 回答