コード例 #1
0
ファイル: DemoForm.cs プロジェクト: khoikhuong/OCRCore
        void UpdateProgressSafe(int value)
        {
            if (value == 0)
            {
                btnLoad.Enabled = true;
                btnRecognizeSelected.Enabled = true;
                btnChooseFile.Enabled        = true;
                lstLoadedImages.Enabled      = true;
                panel1.Enabled = true;
                panel2.Enabled = true;
                panel3.Enabled = true;

                IntPtr hBmp = IntPtr.Zero;
                int    res  = SmartOcrSdkExports.OCR_GetHBITMAP_FromPageImage(m_nSelectedPageIndex, ref hBmp);
                if (res != SmartOcrSdkExports.RES_ERROR)
                {
                    pbPreview.Image = Bitmap.FromHbitmap(hBmp);
                }
                if (!m_Dictionary_Page.ContainsKey(m_nSelectedPageIndex))
                {
                    m_Dictionary_Page.Add(m_nSelectedPageIndex, null);
                }

                var Template_ID = CheckExitsTemplate();

                if (Template_ID.HasValue)
                {
                    LoadDynamicInput(Template_ID.Value);
                    LoadDynamicRectangle(Template_ID.Value);
                }
                else
                {
                    MessageBox.Show("Template Incorrect");
                    if (MessageBox.Show("Bạn có muốn tạo template cho file?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        var      m_Path      = lstLoadedImages.SelectedItem.ToString();
                        string   m_Extention = Path.GetExtension(m_Path);
                        string[] m_Str       = m_Extention.Split('_');

                        if (m_Str.Length > 1)
                        {
                            m_Path = m_Path.Replace("_" + m_Str[1], "");
                        }
                        FileTemplateOCR_DTO.m_Path = m_Path;
                        var frmTemplate = new DemoTemplateForm();
                        frmTemplate.MaximizeBox = false;
                        frmTemplate.Show(this);
                    }
                }
            }
            prgRecognition.Value = value;
        }
コード例 #2
0
        void UpdateProgressSafe(int value)
        {
            if (value == 0)
            {
                btnChooseFile.Enabled   = true;
                lstLoadedImages.Enabled = true;
                panel1.Enabled          = true;
                panel2.Enabled          = true;
                //panel3.Enabled = true;

                IntPtr hBmp = IntPtr.Zero;

                int res = SmartOcrSdkExports.OCR_GetHBITMAP_FromPageImage(m_nSelectedPageIndex, ref hBmp);
                if (res != SmartOcrSdkExports.RES_ERROR)
                {
                    pbPreview.Image = Bitmap.FromHbitmap(hBmp);
                }
            }
            prgRecognition.Value = value;
        }
コード例 #3
0
        void lstLoadedImages_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstLoadedImages.SelectedItem != null)
            {
                if (pbPreview.Image != null)
                {
                    pbPreview.Image.Dispose();
                }
                Remove();
                if (m_bActiveRecognition == false)
                {
                    m_nSelectedPageIndex = lstLoadedImages.Items.Count > 0 ? (m_Page + lstLoadedImages.SelectedIndex) : -1;
                    if (m_nSelectedPageIndex >= 0)
                    {
                        IntPtr hBmp = IntPtr.Zero;
                        int    res  = SmartOcrSdkExports.OCR_GetHBITMAP_FromPageImage(m_nSelectedPageIndex, ref hBmp);
                        if (res != SmartOcrSdkExports.RES_ERROR)
                        {
                            pbPreview.Image = Bitmap.FromHbitmap(hBmp);
                        }
                        var Template_ID = Convert.ToInt32(txtTemplate_ID.Text);
                        if (!m_Dictionary_Page.ContainsKey(m_nSelectedPageIndex))
                        {
                            m_Dictionary_Page.Add(m_nSelectedPageIndex, Template_ID);
                            btnChooseFile.Enabled   = false;
                            lstLoadedImages.Enabled = false;
                            panel1.Enabled          = false;
                            panel2.Enabled          = false;

                            m_bCancelRequested   = false;
                            m_bActiveRecognition = true;
                            prgRecognition.Value = 0;
                            Thread threadRecognition = new Thread(new ThreadStart(RecognizeSelectedThreadProc));
                            threadRecognition.Start();
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: DemoForm.cs プロジェクト: khoikhuong/OCRCore
        private void lstLoadedImages_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstLoadedImages.SelectedItem != null)
            {
                if (pbPreview.Image != null)
                {
                    pbPreview.Image.Dispose();
                }

                #region note
                //int nPageCount = SmartOcrSdkExports.OCR_GetPageCount();
                //if (nPageCount >= 0)
                //{
                //    SmartOcrSdkExports.OCR_RemoveAllPages();
                //}

                //string ext = Path.GetExtension(lstLoadedImages.SelectedItem.ToString());
                //string filePath = lstLoadedImages.SelectedItem.ToString();
                //string[] page = ext.Split('_');
                //int pageIndex = 0, index  = 0;
                //if (page != null)
                //{
                //    ext = page[0].ToString();
                //    if(page.Length > 1)
                //    {
                //        string strPage = page[1];
                //        index = strPage.Length;
                //        pageIndex = (Convert.ToInt16(strPage.Substring(4))) - 1;
                //        filePath = filePath.Replace("_" + strPage, "");
                //    }

                //}
                //if (ext == ".pdf")
                //{
                //    SmartOcrSdkExports.OCR_AddPagesFromPDF(filePath, null, IntPtr.Zero);

                //    #region Note
                //    //PdfDocument doc = new PdfDocument();
                //    //doc.LoadFromFile(filePath);
                //    //Image emf = doc.SaveAsImage(0, Spire.Pdf.Graphics.PdfImageType.Bitmap);
                //    //pbPreview.Image = emf;
                //    #endregion
                //    ExtentionFile = 0;
                //}
                //else
                //{
                //    SmartOcrSdkExports.OCR_AddPageFromImage(filePath);
                //   // pbPreview.Image = Bitmap.FromFile(filePath);
                //    ExtentionFile = 0;
                //}
                #endregion
                Remove();
                if (m_bActiveRecognition == false)
                {
                    m_nSelectedPageIndex = lstLoadedImages.Items.Count > 0 ? lstLoadedImages.SelectedIndex : -1;
                    if (m_nSelectedPageIndex >= 0)
                    {
                        LoadDynamicInput();

                        IntPtr hBmp = IntPtr.Zero;

                        int res = SmartOcrSdkExports.OCR_GetHBITMAP_FromPageImage(m_nSelectedPageIndex, ref hBmp);
                        if (res != SmartOcrSdkExports.RES_ERROR)
                        {
                            pbPreview.Image = Bitmap.FromHbitmap(hBmp);

                            #region "Resize image"
                            //Image MyImage = Bitmap.FromHbitmap(hBmp);

                            //Bitmap MyBitMap = new Bitmap(MyImage, panel1.Width + 200, panel1.Height + 200);

                            //Graphics Graphic = Graphics.FromImage(MyBitMap);

                            //Graphic.InterpolationMode = InterpolationMode.High;

                            //pbPreview.Image = MyBitMap;
                            #endregion
                        }

                        if (!m_Dictionary_Page.ContainsKey(m_nSelectedPageIndex))
                        {
                            btnLoad.Enabled = false;
                            btnRecognizeSelected.Enabled = false;
                            btnChooseFile.Enabled        = false;
                            lstLoadedImages.Enabled      = false;
                            btnRemoveRegion.Enabled      = false;
                            panel1.Enabled = false;
                            panel2.Enabled = false;
                            panel3.Enabled = false;

                            m_bCancelRequested   = false;
                            m_bActiveRecognition = true;
                            prgRecognition.Value = 0;

                            //@Tuan: Nen xem xet cai nay
                            Thread threadRecognition = new Thread(new ThreadStart(RecognizeSelectedThreadProc));
                            threadRecognition.Start();
                        }
                        else
                        {
                            var Template_ID = CheckExitsTemplate();
                            if (Template_ID.HasValue)
                            {
                                LoadDynamicInput(Template_ID.Value);
                                LoadDynamicRectangle(Template_ID.Value);
                            }
                            else
                            {
                                MessageBox.Show("Template Incorrect");
                                if (MessageBox.Show("Bạn có muốn tạo template cho file?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    var      m_Path      = lstLoadedImages.SelectedItem.ToString();
                                    string   m_Extention = Path.GetExtension(m_Path);
                                    string[] m_Str       = m_Extention.Split('_');

                                    if (m_Str.Length > 1)
                                    {
                                        m_Path = m_Path.Replace("_" + m_Str[1], "");
                                    }
                                    FileTemplateOCR_DTO.m_Path = m_Path;
                                    var frmTemplate = new DemoTemplateForm();
                                    frmTemplate.MaximizeBox = false;
                                    frmTemplate.Show(this);
                                }
                            }
                        }
                    }
                }
            }
        }