Ejemplo n.º 1
0
        /// <summary>
        /// 获取截屏区域的文字
        /// </summary>
        /// <param name="bitmap"></param>
        private void GetSnapArea(Bitmap bitmap)
        {
            Show.Text = null;
            DateTime startTime = DateTime.Now;
            string   str       = OCRApi.getFileBase64(bitmap);
            string   text      = OCRApi.GetWords(str, true);

            OCRApi.Str2Json(text, WordsNum, Show);
            DateTime endTime  = DateTime.Now;
            TimeSpan duration = endTime - startTime;

            NeedTime.Text   = string.Format("{0:N3}", duration.TotalSeconds) + " S";
            this.Visibility = Visibility.Visible;
        }
Ejemplo n.º 2
0
        private void OpenPic_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "PNG|*.png|JPG|*.jpg|JPEG|*.jpeg|BMP|*.bmp|TIFF|*.tiff|WEBP|*.webp";
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == true)
            {
                Show.Text = null;
                DateTime startTime = DateTime.Now;
                string   text      = OCRApi.GetWords(ofd.FileName);
                OCRApi.Str2Json(text, WordsNum, Show);
                DateTime endTime  = DateTime.Now;
                TimeSpan duration = endTime - startTime;
                NeedTime.Text = string.Format("{0:N3}", duration.TotalSeconds) + " S";
            }
        }
Ejemplo n.º 3
0
        private void Grid_Drop(object sender, System.Windows.DragEventArgs e)
        {
            string fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

            string[] path   = fileName.Split('.');
            string   suffix = path[path.Length - 1];

            if (suffix == "png" || suffix == "jpg" || suffix == "webm" || suffix == "jpeg" || suffix == "tiff")
            {
                Show.Text = null;
                DateTime startTime = DateTime.Now;
                string   text      = OCRApi.GetWords(fileName);
                OCRApi.Str2Json(text, WordsNum, Show);
                DateTime endTime  = DateTime.Now;
                TimeSpan duration = endTime - startTime;
                NeedTime.Text = string.Format("{0:N3}", duration.TotalSeconds) + " S";
            }
            else
            {
                MessageBox.Show("文件格式错误");
            }
        }