我在做一个C#Winform的程序数据库中放的是图片的路径,如何在数据库中取出显示在pictureBox中,这个pictureBox是我创建了我要把这个pictureBox加到tableLayoutPanel实现动态显示图片?求高手指教

解决方案 »

  1.   


    private Bitmap MyImage ;
    public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
    {
       // Sets up an image object to be displayed.
       if (MyImage != null)
       {
          MyImage.Dispose();
       }   // Stretches the image to fit the pictureBox.
       pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage ;
       MyImage = new Bitmap(fileToDisplay);
       pictureBox1.ClientSize = new Size(xSize, ySize);
       pictureBox1.Image = (Image) MyImage ;
    }
      

  2.   

    http://www.pczpg.com/html/bianchengkaifa/C_/20091028/21679.html
    中第二个BtnDownLoad_click或许和你说的有点关系
    关于实现动态显示图片,我帮不上了
      

  3.   

    从数据库读图像,并显示在pictruebox中172  /**//// <summary>
    173  /// 从数据库中读取bitmap图片并显示
    174  /// </summary>
    175  /// <param name="sender"></param>
    176  /// <param name="e"></param>
    177  private void button2_Click(object sender, System.EventArgs e)
    178  {
    179   SqlConnection conn = new SqlConnection("server=192.168.2.200;integrated security = sspi;database = northwind");
    180   SqlCommand cmd = new SqlCommand("select * from imgtable where imgname like '%bmp%'",conn);
    181   conn.Open();
    182   SqlDataReader dr;
    183   try
    184   {
    185    dr = cmd.ExecuteReader();
    186    dr.Read();
    187    System.Data.SqlTypes.SqlBinary sb = dr.GetSqlBinary(2);
    188    //或byte[] imageData = (byte[])dr[2];
    189    MemoryStream ms = new MemoryStream(sb.Value);//在内存中操作图片数据
    190    Bitmap bmp = new Bitmap(Bitmap.FromStream(ms));
    191    this.pictureBox1.Image = bmp;
    192    dr.Close();
    193   }
    194   catch(Exception ex)
    195   {
    196    MessageBox.Show(ex.Message);
    197   }
    198   finally
    199   {
    200    conn.Close();
    201   }
    202  }
    下面是表结构,第3列是imageCreate table [imgtable](
     [imgid] [int] IDENTITY(1,1) NOT NULL,
     [imgname] [varchar](100) COLLATE Chinese_PRC_CI_AS NULL,
     [imgData] [image] NULL,
     PRIMARY KEY CLUSTERED
     (
     [imgid]
     ) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      

  4.   

    你数据库存放的是图片的路径,得到路径不就可以得到图片么?Image img = Image.FromFile(filePath);
      

  5.   

    Image img = Image.FromFile(filePath);动态显示时调用代码在执行一次 pictureBox1.Image = (Image) MyImage ;