8 winform图片上传,读取,删除
//上传
private void BtnImgAdd_Click(object sender, EventArgs e)
{
if (this.Code != "")
{
OpenFileDialog dlgOpenFile = new OpenFileDialog();
dlgOpenFile.Filter = "JPG图片(*.jpg)|*.jpg|BMP图片(*.bmp)|*.bmp|GIF图片(*.gif)|*.gif";
dlgOpenFile.ShowReadOnly = true;
if (dlgOpenFile.ShowDialog() == DialogResult.OK)
{
//判断图片大小
// string image = dlgOpenFile.FileName;
string picpath = dlgOpenFile.FileName;
Guid guid = Guid.NewGuid();
string path = System.Windows.Forms.Application.StartupPath + "//images//" + guid.ToString() + ".jpg";
//判断图片尺寸大小
Image imgs = Image.FromFile(picpath);
FileInfo fi = new FileInfo(picpath);
long contentlenth = fi.Length;
if (contentlenth > 2000 * 1024)
{
MessageBox.Show("图片体积过大");
return;
}
if (imgs.Width > 500 || imgs.Height > 500)
{
MessageBox.Show("图片尺寸过大");
return;
}
File.Copy(picpath, path);//删除文件夹下图片
pictureBox1.Image = imgs;
pictureBox1.Image