//从数据库中获取图片然后将图片绘制到picturebox中去 Graphics g = this.pictureBox1.CreateGraphics(); SqlConnection conn = new SqlConnection(this.minechiefCertPaper); string strSql = "SELECT zhaopian from coalchiefneed where tablename='t_ap_busiCoalChiefCertify' and fid=5"; SqlCommand cmd = new SqlCommand(strSql, conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); //创建一个内存 读取数据流,将读取的数据库的图片以二进制的byte[]流存入内存中。 MemoryStream ms = new MemoryStream((byte[])reader["zhaopian"]); reader.Close(); conn.Close(); Image zhaopian = Image.FromStream(ms, true); //0,0表示picturebox的顶点0,0,宽和高就是picturebox的宽和高 Rectangle rect = new Rectangle(0,0,pictureBox1.Width,pictureBox1.Height); //这里绘制的是图片的内容区域,0,0表示从图片的顶点开始绘制起,zhoapian.width,zhaopian.height表示图片的宽度和高度,也就是绘制整张图片 Rectangle imageRect = new Rectangle(0, 0, zhaopian.Width,zhaopian.Height); g.DrawImage(zhaopian, rect, imageRect, GraphicsUnit.Pixel);