• 添加图片


    //添加图片按钮
            private void stgl_xz_but_tupian_Click(object sender, EventArgs e)
            {
                tianjiatupian.Filter = "*jpg|*.jpg|*bmp|*.bmp|*gif|*.gif";//定义可以打开的文件类型
                DialogResult dia = tianjiatupian.ShowDialog();
                if (dia == DialogResult.OK)
                {
                    string filename = tianjiatupian.FileName;
                    FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);//将图片读入流中
                    st.Imgbytes= new byte[fs.Length];//二进制数组,用以临时存储图像的二进制编码
                    BinaryReader br = new BinaryReader(fs);//二进制读取器
                    st.Imgbytes = br.ReadBytes(Convert.ToInt32(fs.Length));//将图片读入到二进制数组中
                    //在图片框中显示图片
                    MemoryStream ms = new MemoryStream(st.Imgbytes, 0, st.Imgbytes.Length);
                    ms.Write(st.Imgbytes, 0, st.Imgbytes.Length);
                    Image img = Image.FromStream(ms);
                    this.stgl_xz_tupian.SizeMode = PictureBoxSizeMode.Zoom;//设置自动适应大小
                    this.stgl_xz_tupian.Image = img;
                }
    
            }
            //清除图片按钮
            private void stgl_xz_but_qingchu_Click(object sender, EventArgs e)
            {
                st.Imgbytes = null;
                this.stgl_xz_tupian.Image = null;
            }
            //鼠标单击列表显示图片
            private void stgl_view_MouseClick(object sender, MouseEventArgs e)
            {
                this.tupianyulan.Image = null;
                //将图像写入内存
                if (stgl_view1.SelectedCells[2].Value.ToString() != "")
                {
                    byte[] imgbytes = (byte[])stgl_view1.SelectedCells[2].Value;
    
                    MemoryStream ms = new MemoryStream(imgbytes, 0, imgbytes.Length);
                    ms.Write(imgbytes, 0, imgbytes.Length);
    
                    Image img = Image.FromStream(ms);
    
                    this.tupianyulan.SizeMode = PictureBoxSizeMode.Zoom;//设置自动适应大小
                    this.tupianyulan.Image = img;
                }
            }
  • 相关阅读:
    自定义主键自增规则 Oracle Mssql(全库唯一标识)
    SQL Server 字符串 参数详解
    js 实现类似C# 委托的那种效果
    网页页面“返回到顶部”
    js substr与substring的区别
    js 格式化时间/Date(1425027069000)/格式化为yyyy-MM-dd HH:mm:ss
    js 设置一个按周期向服务器发送请求 推荐是用 setTimeOut函数
    jquery 几个常用的选择器
    Oracle
    小议出参入参
  • 原文地址:https://www.cnblogs.com/Tirisfal/p/4396192.html
Copyright © 2020-2023  润新知