现在的位置: 首页 > 综合 > 正文

打开图片

2013年12月04日 ⁄ 综合 ⁄ 共 1191字 ⁄ 字号 评论关闭
                                                                                                                                                                        OpenFileDialog ofd=new OpenFileDialog();//过滤格式
ofd.Filter="JPEG格式(*.jpg;*.JPEG)|*.jpg|GIF格式(*.gif;*.GIF)|*.gif|BMP图像(*.bmp;*.BMP)|*.bmp|所有文件(*.*)|*.*";
if(ofd.ShowDialog()==DialogResult.OK)
{
//根据打开的图像文件创建原始图像大小的Bitmap对像
Bitmap bitmap= new Bitmap(ofd.OpenFile()); 
//缩放到170像素宽,200像素高
Bitmap image=new Bitmap(bitmap,170,200);
//显示到PictureBox1中
this.pictureBoxEmployee.Image=image;
//获取图片路径及图片名
}
FileStream fs=new FileStream(this.stbEmp.Text,FileMode.Open,FileAccess.Read);
long len=fs.Length;
OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../Data/*.mdb");
OleDbCommand cmd=new OleDbCommand("update table set Photo=@img where id='"+txtId.Text+"'",con);
cmd.Parameters.Add(new OleDbParameter("@img",OleDbType.Binary,(int)len,"Photo"));
cmd.Parameters["@img"].Direction=System.Data.ParameterDirection.Input;
byte[] bytes=new byte[len];
fs.Read(bytes,0,(int)len);
cmd.Parameters["@img"].Value=bytes;
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("图片载入成功!"); 
}
catch(Exception err)
{
MessageBox.Show(err.ToString());
}
 

抱歉!评论已关闭.