public static DialogResult ShowCustomDialog(PaperProfile paperProfile) { using (PaperProfileDialog dialog = new PaperProfileDialog(paperProfile)) { return(dialog.ShowDialog()); } }
public void DeletePaperProfile(PaperProfile paperProfile) { string path = Path.Combine(_path, $"{paperProfile.Name}"); if (File.Exists(path)) { File.Delete(path); } }
public void AddOrUpdatePaperProfile(PaperProfile paperProfile) { string path = Path.Combine(_path, $"{paperProfile.Name}"); using (BinaryWriter binary = new BinaryWriter(File.OpenWrite(path))) { binary.Write(paperProfile.Serialize()); } }
private void Btn_Accept_Click(object sender, EventArgs e) { string nameProfile = txt_ProfileName.Text.Trim(); if (string.IsNullOrWhiteSpace(nameProfile)) { MessageBox.Show("Vui lòng không để trống tên profile.", "Thiếu thông tin."); return; } if (!int.TryParse(txt_ProfileWidth.Text.Trim(), out int width)) { MessageBox.Show("Vui lòng chỉ nhập số khi khai báo kích thước giấy.", "Thiếu thông tin."); return; } if (!int.TryParse(txt_ProfileHeight.Text.Trim(), out int height)) { MessageBox.Show("Vui lòng chỉ nhập số khi khai báo kích thước giấy.", "Thiếu thông tin."); return; } if (cbb_PaperProfile.Items.Contains(nameProfile)) { if (!_editMode) { if (MessageBox.Show("Profile này đã có trước, bạn muốn ghi đè lên?", "Trùng lập.", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } } } if (_selectedPaperProfile == null) { _selectedPaperProfile = new PaperProfile("", 0, 0); } _selectedPaperProfile.Name = nameProfile; _selectedPaperProfile.Width = width; _selectedPaperProfile.Height = height; _paperResource.AddOrUpdatePaperProfile(_selectedPaperProfile); MessageBox.Show("Thao tác thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (_createCommand) { DialogResult = DialogResult.OK; Close(); } else { cbb_PaperProfile.UpdateUI(_paperResource.Profiles, nameProfile); } }
public List <Dictionary <string, string> > GetUtf8TextBaseOnRegions(IImage image, ROIProfile regions, out IImage imgdrawed) { imgdrawed = null; List <Dictionary <string, string> > result = new List <Dictionary <string, string> >(); if (image == null) { return(result); } if (regions == null) { return(result); } IPaperResource paperResource = PaperResource.DefaultInstance(); PaperProfile paperProfile = paperResource.GetPaperProfile(regions.PaperSize); if (paperProfile == null) { return(result); } InitialLaguagePack(regions); Dictionary <string, string> onePage = new Dictionary <string, string>(); Image <Gray, byte> imgOriginal = image is Image <Gray, byte>?image as Image <Gray, byte> : new Image <Gray, byte>(image.Bitmap); Image <Bgr, byte> imgColor = imgOriginal.Copy().Convert <Bgr, byte>(); foreach (ROI region in regions.Regions) { Rectangle rect = region.RegionRectangle.ConvertActualyImageSizeToImageResize(paperProfile, imgOriginal.Bitmap); imgOriginal.ROI = rect; imgColor.Draw(rect, new Bgr(Color.Red), 1); _tesseracts[region.Language].SetImage(imgOriginal.Copy()); string txt = _tesseracts[region.Language].GetUTF8Text(); MatchCollection ms = Regex.Matches(txt, region.GenaratedRegexPattern, RegexOptions.Multiline); Match m = ms.Cast <Match>().OrderByDescending(s => s.Length).Take(1).FirstOrDefault(); onePage.Add(region.RegionName, m?.Value); imgOriginal.ROI = Rectangle.Empty; } imgdrawed = imgColor; result.Add(onePage); return(result); }
private void Cbb_PaperProfile_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cbb = sender as ComboBox; if (cbb.SelectedItem != null) { _selectedPaperProfile = _paperResource.GetPaperProfile(cbb_PaperProfile.SelectedItem.ToString()); if (_selectedPaperProfile != null) { btn_Edit.Enabled = true; btn_Delete.Enabled = true; txt_ProfileName.Text = _selectedPaperProfile.Name; txt_ProfileWidth.Text = _selectedPaperProfile.Width.ToString(); txt_ProfileHeight.Text = _selectedPaperProfile.Height.ToString(); } else { btn_Edit.Enabled = false; btn_Delete.Enabled = false; txt_ProfileName.Text = ""; txt_ProfileWidth.Text = ""; txt_ProfileHeight.Text = ""; } } else { btn_Edit.Enabled = false; btn_Delete.Enabled = false; txt_ProfileName.Text = ""; txt_ProfileWidth.Text = ""; txt_ProfileHeight.Text = ""; } txt_ProfileName.Enabled = false; txt_ProfileWidth.Enabled = false; txt_ProfileHeight.Enabled = false; }
private PaperProfileDialog(PaperProfile paperProfile) { InitializeComponent(); _selectedPaperProfile = paperProfile; _createCommand = true; }
/// <summary> /// Chuyển đổi một Rectangle từ vị trí ở kích thước thực của ảnh sang vị trí trong kíc thước đã thay đổi /// </summary> /// <param name="rectangle">Rect trong kích thước thật</param> /// <param name="paperProfile">Thông tin kích thước thật của ảnh</param> /// <param name="img">Thông tin kích thức ảnh cần chuyển qua</param> /// <returns></returns> public static Rectangle ConvertActualyImageSizeToImageResize(this Rectangle rectangle, PaperProfile paperProfile, Image img) { if (paperProfile == null) { return(Rectangle.Empty); } if (img == null) { return(Rectangle.Empty); } double xRatio = (double)rectangle.X / paperProfile.Width; double yRatio = (double)rectangle.Y / paperProfile.Height; double widthRatio = (double)rectangle.Width / paperProfile.Width; double heightRatio = (double)rectangle.Height / paperProfile.Height; rectangle.X = (int)((xRatio * img.Width) / ROI.Accuracy); rectangle.Y = (int)((yRatio * img.Height) / ROI.Accuracy); rectangle.Width = (int)((widthRatio * img.Width) / ROI.Accuracy); rectangle.Height = (int)((heightRatio * img.Height) / ROI.Accuracy); return(rectangle); }