110,577
社区成员
发帖
与我相关
我的任务
分享
private void btnUpload_Click(object sender, EventArgs e)
{
openPic.Title = "Choose Picture";
openPic.Filter = "JPEG(*.jpg)|*.jpg|PNG(*.png)|*.png";
if (openPic.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openPic.FileName))
{
if (openPic.OpenFile().Length > 1024 * 1024 * 2)
{
MessageBox.Show("图片不得超过2M");
return;
}
string image = openPic.FileName;
string picpath = openPic.FileName;
Guid guid = Guid.NewGuid();
this.txtPhoto.Text = openPic.FileName;
if (!Directory.Exists(Application.StartupPath + "\\image"))
{
Directory.CreateDirectory(Application.StartupPath + "\\image");
}
this.txtPhoto.Tag = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
File.Copy(openPic.FileName, Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.Image = Image.FromFile(Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.ImageLocation = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
}
else
{
MessageBox.Show("图片不能为空");
return;
}
}
}