private void insertInfo() { try { string movieName = nameBox.Text; //添加获取电影名称的代码 string startTime = timeBox.Text; //添加获取上映时间的代码 string director = directorBox.Text; //添加获取导演的代码 string actors = actorBox.Text; //添加获取演员的代码 string introduction = introBox.Text; //添加获取简介的代码 string[] newPath = new string[2]; newPath = copyPM();//将上载的文件复制到指定路径下,并返回路径 //预留接口,为上载图像信息做准备 imageSearch imgSearch = new imageSearch(); string imgInfo = imgSearch.getPHash(newPath[0]);;// 获取上载图像的灰度值 MySqlConnection conn = new MySqlConnection(Conn); conn.Open(); string sql = "insert into db_movie_info value('" + movieName + "','" + startTime + "','" + director + "','" + actors + "','" + introduction + "','" + newPath[0] + "','" + newPath[1] + "','" + imgInfo + "');";//填写插入语句; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); System.Windows.MessageBox.Show("上载成功!"); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "插入数据库失败"); } }
private void imageSearch_Click(object sender, RoutedEventArgs e) { try { imageSearch imgSearch = new imageSearch(); //add by center var pHash = imgSearch.getPHash(image.Text); //获取上载图像的phash指 int[] imgOrder = imgSearch.pHashSearchResult(pHash); ///获取与数据库中图像的比较结果 //string upGray = imgSearch.getGray(image.Text);//获取上载图像的灰度值 /*int[] imgOrder = imgSearch.searchResult(upGray);*/ //获取与数据库中图像的比较结果 count = 0; n = 0; string sql = "select * from db_movie_info;"; getMovieInfo = new string[100, 7];//初始化数组 MySqlConnection conn = new MySqlConnection(Conn); conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //查找数组中的索引,需要理解一下 getMovieInfo[Array.IndexOf(imgOrder, count), 0] = reader["movie_name"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 1] = reader["time"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 2] = reader["director"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 3] = reader["actor"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 4] = reader["content"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 5] = reader["poster_path"].ToString(); getMovieInfo[Array.IndexOf(imgOrder, count), 6] = reader["movie_path"].ToString(); count++; } for (int i = 3; i < count; i++)//只取前3位 { getMovieInfo[i, 0] = null; } count = 3; showInfo(); downButton.IsEnabled = true; upButton.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "查询失败"); } }
public MainWindow() { InitializeComponent(); homePage hp = new homePage(); if (test == 1) { hp.Show(); this.Close(); var filePath = "C:\\Users\\MSI-PC\\Desktop\\database\\你的名字原版.jpg"; var comparePath = "C:\\Users\\MSI-PC\\Desktop\\database\\你的名字旋转.jpg"; imageSearch imgSearch = new imageSearch(); var oP = imgSearch.getPHash(filePath); var oA = imgSearch.getAHash(filePath); var pP = imgSearch.getPHash(comparePath); var pA = imgSearch.getAHash(comparePath); var ansP = imgSearch.pHashCompare(oP, pP); var ansA = imgSearch.pHashCompare(oA, pA); double ans1 = ansP / 64.0, ans2 = ansA / 64.0; SaveImage(oP, "op.jpg"); SaveImage(oA, "oA.jpg"); SaveImage(pP, "pP.jpg"); SaveImage(pA, "pA.jpg"); } }