首页 > Windows开发 > 详细

C# winform 上传图片

时间:2021-08-22 21:24:24      阅读:23      评论:0      收藏:0      [点我收藏+]


1. 上传图片并 保存到自己的路径

        private void gtisButton1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialogTemp = new OpenFileDialog();
            openFileDialogTemp.Title = "选择要上传的图片";
            openFileDialogTemp.Filter = "All Files(*.*)|*.*|位图(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg";

            DialogResult dr = openFileDialogTemp.ShowDialog();

            textBox1.Text = openFileDialogTemp.FileName;
            if (!File.Exists(openFileDialogTemp.FileName))
            {
                MessageBox.Show("照片为空,请选择图片");
                return;
            }

            if (dr == DialogResult.OK)
            {
                string image = openFileDialogTemp.FileName;
                string picpath = openFileDialogTemp.FileName;

                pictureBox1.Image = Image.FromFile(image);
                this.pictureBox1.Text = image;

                string id = "111";
                File.Copy(openFileDialogTemp.FileName, Application.StartupPath + "\\Image\\" + id + ".jpg");

            }

        }

 

2. 参考链接

https://www.cnblogs.com/right_forever/archive/2011/05/31/2064257.html

https://www.cnblogs.com/lingbohome/p/4655043.html

 

C# winform 上传图片

原文:https://www.cnblogs.com/lg-lg/p/15173208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!