private void btnLogin_Click(object sender, EventArgs e) { if (tbxApiKey.Text != "" && tbxSecretKey.Text != "") { Program.ApiKey = tbxApiKey.Text; Program.SecretKey = tbxSecretKey.Text; var client = new Baidu.Aip.Ocr.Ocr(Program.ApiKey, Program.SecretKey); var result = client.GeneralBasic(BitmapByte(Icon.ToBitmap()), null); AccessTokenModel a = JsonConvert.DeserializeObject <AccessTokenModel>(result.ToString()); if (a.error_msg != null) { string rz = "验证失败!请输入有效的ApiKey和SecretKey!\n"; MessageBox.Show(rz); } else { MessageBox.Show("成功登录,登录id:" + a.log_id.ToString()); this.DialogResult = DialogResult.OK; } } else { MessageBox.Show("请输入值!"); } }
//========================计时器事件=========================== private void tmReadSeconds_Tick(object sender, EventArgs e) { Rectangle rect = new System.Drawing.Rectangle(); IntPtr mainHandle = hwndChild; GetWindowRect(mainHandle, ref rect); ScreenCapture t = new ScreenCapture(); Image img = t.CaptureWindow(mainHandle); Bitmap bit = new Bitmap(img); pictureBox1.Image = bit; var client = new Baidu.Aip.Ocr.Ocr(ApiKey, SecretKey); // 通用文字识别 var result = client.GeneralBasic(BitmapByte(bit), null); AccessTokenModel ocrResult = JsonConvert.DeserializeObject <AccessTokenModel>(result.ToString()); string rz = ""; if (ocrResult.error_msg != null) { rz = "QPS已达到峰值!"; } else { if (ocrResult.words_result.HasValues) { //rz = result["words_result"].First.SelectToken("words").ToString(); rz = ocrResult.words_result.First.SelectToken("words").ToString(); //=======================从这里开始写轴=========================== for (int i = 0; i < listUB.Count; i++) { ClickCharacterByUBTime(rz, listUB[i].ubTime, listUB[i].clickWho); } } else { rz = "无法识别"; } } AddTextToBoard(rz); }