private void Ocr(string fileName, string type, Dictionary <string, object> options) { if (String.IsNullOrEmpty(fileName)) { return; } // 调用通用文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获 try { // 带参数调用通用文字识别, 图片参数为本地图片,options可选 JToken result; byte[] image = File.ReadAllBytes(fileName); switch (type) { case "hand": if (null == options) { result = client.Handwriting(image); } else { result = client.Handwriting(image, options); } break; default: result = client.GeneralBasic(image); break; } image = null; JArray wordsArray = (JArray)result["words_result"]; string wordsStr = ""; for (int i = 0; i < wordsArray.Count; i++) { wordsStr += wordsArray[i]["words"] + "\r\n"; } textBox1.Text = wordsStr; } catch (Exception ex) { Console.WriteLine(ex); } }