C# WinForm 实现增删改查等功能(Access版) 系列之七-图片处理

图片处理模块设计与实现

        /// <summary>

        /// 获得上传图片的图片名称

        /// </summary>

        /// <param name="txtName"></param>

        /// <returns></returns>

        public string getStrOfPictureBox(string txtName)

        {

            string strpictrue = "";

            string name = txtName;

            OleDbConnection conn = GetConnection();

            string sqlText = "select 图片 from MResume where 姓名=@name order by id asc";

            OleDbCommand cmd = new OleDbCommand(sqlText, conn);

            cmd.Parameters.AddWithValue("@name", name);

            try

            {

                conn.Open();

                OleDbDataReader reader = cmd.ExecuteReader();

                if (reader.Read())

                {

                    if (!reader[0].ToString().Equals("0") && reader[0].ToString()!="" && reader[0].ToString()!=null)

                    {

                        strpictrue = reader[0].ToString();

                    }

                    else

                    {

                        strpictrue = Application.StartupPath + "\\Image\\nophoto.jpg";

                    }

                }

                /*DataTable dt = new DataTable();

                 OleDbDataAdapter oda = new OleDbDataAdapter(sqlText, conn);

                 oda.Fill(dt);

                 dataGridView1.DataSource = dt;

                 */

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

            finally

            {

                conn.Close();

            }

            return strpictrue;

        }

打开对话框,选择图片,上传图片

/// <summary>

        /// UploadImages

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

        {

          //本方法来源于Spirit's Home http://www.7788sky.cn/,原文地址:http://www.7788sky.cn/post/csharp_winform_upload_image.html

         // openFileDialog1.Filter = "All files (*.*)|*.*|jpg files (*.jpg)|*.jpg";

            openFileDialog1.Filter = "jpg files (*.jpg)|*.jpg";

            DialogResult dr = openFileDialog1.ShowDialog();

            if (dr == DialogResult.OK)

            {

              string image = openFileDialog1.FileName;

              string picpath = openFileDialog1.FileName;

              DateTime dt1 = new DateTime(1970, 1, 1);

              TimeSpan ts = DateTime.Now - dt1;

              timeStamp = (long)ts.TotalMilliseconds;

              //string id = DateTime.Now.Millisecond.ToString();

              picPerson.Image = Image.FromFile(image);

              File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Image\\" + timeStamp.ToString() + ".jpg");

              lblImage.Text = timeStamp.ToString();    //设置图片字符串

            }

        }

转载于:https://www.cnblogs.com/maxblog/archive/2010/04/01/1702590.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值