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 ; }
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 ;
}
中第二个BtnDownLoad_click或许和你说的有点关系
关于实现动态显示图片,我帮不上了
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]