zoukankan      html  css  js  c++  java
  • C/S 图片操作

    从数据库中读取:
    方法一:
    SqlCommand Cmd = new SqlCommand("SELECT * FROM student", MyCn);
    SqlDataAdapter da = new SqlDataAdapter(Cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "student");
    Byte[] byteBLOBData =  new Byte[0];
    byteBLOBData = (Byte[])(ds.Tables["student"].Rows[index]["ZP"]);
    MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
    this.pictureBox2.Image= Image.FromStream(stmBLOBData);

    方法二:
    OleDbDataAdapter MyDa=new OleDbDataAdapter("select ZP from picture",MyCn);
       DataSet ds=new DataSet();
       MyDa.Fill(ds,"picture");
    foreach(DataRow rFirst in ds.Tables["picture"].Rows)
        {
         bData=(byte[])rFirst["ZP"];
        }

    MemoryStream stream=new MemoryStream(bData,true);
    //MemoryStream stream=new MemoryStream(bData);
        // Create a bitmap from the stream
        Bitmap bmp = new Bitmap(stream);

        try
        {
         //Showing
         this.pictureBox1.Image=bmp;
         //this.pictureBox1.Image=Image.FromStream(stream);
        }
        catch{};
        // Close the stream
        stream.Close();

    =========================================================================
    插入数据库中:
    SqlCommand MyCmd=new SqlCommand("INSERT INTO student(XH,ZP) VALUES(@XH,@ZP)",MyCn);

       //Read jpg into file stream, and from there into Byte array.
       FileStream fsBLOBFile =  new FileStream(strBLOBFilePath,FileMode.Open, FileAccess.Read);
       Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
       fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
       fsBLOBFile.Close();

       MyCmd.Parameters.Add("@XH",this.txtBox_XH.Text.Trim());

       //Create parameter for insert command and add to SqlCommand object.
       SqlParameter prm = new  SqlParameter("@ZP", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false,0, 0, null, DataRowVersion.Current, bytBLOBData);
       MyCmd.Parameters.Add(prm);

       
       try
       {
        MyCn.Open();
        MyCmd.ExecuteNonQuery();
        MessageBox.Show("保存到数据库成功!","提示");
       }
       catch(Exception ex)
       {
        MessageBox.Show(ex.Message);
       }
       MyCn.Close();

  • 相关阅读:
    001 :PCL 的基本文件类型PCD的读入和写入操作
    CMake +Vs2017+快速搭建pcl1.9.1环境
    Window 10 PCL-1.91+VS2017 源码编译以及安装pcl
    Eigen3+Cmake+Vs2017源码编译
    将Opencv加入到环境变量中
    004 :opencv 中矩阵操作以及通过内存的方式取像素
    ubuntu16.04与win10双系统安装 无法将grub-efi-amd64-signed 软件包安装到/target/中
    简单了解一下PyTest-sq
    软件测试工程师笔试题
    TT-反射-对象拷贝
  • 原文地址:https://www.cnblogs.com/RobotTech/p/532949.html
Copyright © 2011-2022 走看看