public LeadRect RectToDocument(LeadRect value) { var resolution = this.Pages.DefaultResolution; return(LeadRect.FromLTRB( PixelsToDocument(resolution, (int)value.Left), PixelsToDocument(resolution, (int)value.Top), PixelsToDocument(resolution, (int)value.Right), PixelsToDocument(resolution, (int)value.Bottom))); }
private void rubberBandMode_RubberBandCompleted(object sender, ImageViewerRubberBandEventArgs e) { // User selected a new rectangle _overlayRect = _imageViewer.ConvertRect( null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadRect.FromLTRB(e.Points[0].X, e.Points[0].Y, e.Points[1].X, e.Points[1].Y)); // We need to change the interactive mode back to "None" ResetInteractiveMode(); }
void _rubberBand_RubberBandCompleted(object sender, ImageViewerRubberBandEventArgs e) { if (_ocrPage == null) { return; } try { _tsMainZoomComboBox.Enabled = false; using (WaitCursor cursor = new WaitCursor()) { if (_viewer.Image != null) { _currentHighlightRect = _viewer.ConvertRect( null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadRect.FromLTRB(e.Points[0].X, e.Points[0].Y, e.Points[1].X, e.Points[1].Y)); if (_currentHighlightRect.Width > 2 && _currentHighlightRect.Height > 2) { OcrZone zone = new OcrZone(); zone.Bounds = _currentHighlightRect; zone.ZoneType = OcrZoneType.Text; zone.CharacterFilters = OcrZoneCharacterFilters.None; _ocrPage.Zones.Clear(); _ocrPage.Zones.Add(zone); _ocrPage.Recognize(null); _recognitionResults.Text = _ocrPage.GetText(0); if (_recognitionResults.Text == "\n" || _recognitionResults.Text == "") { Messager.ShowInformation(this, "No text was recognized."); } } } } } catch (Exception ex) { Messager.ShowError(this, ex); } finally { _viewer.Invalidate(); _tsMainZoomComboBox.Enabled = true; } }
private static RasterImage CreateTextFooter(LeadSize size, string tag) { var bpp = 24; var byteOrder = RasterByteOrder.Bgr; var viewPerspective = RasterViewPerspective.TopLeft; var image = new RasterImage(RasterMemoryFlags.Conventional, size.Width, size.Height, bpp, byteOrder, viewPerspective, null, null, 0); var fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White)); fill.Run(image); using (var graphics = RasterImagePainter.CreateGraphics(image)) { using (var brush = new SolidBrush(Color.Black)) { using (var font = new Font(FontFamily.GenericSansSerif, size.Width / 128)) { var pos = new PointF(0, 0); { SizeF stringSize = new SizeF(); stringSize = graphics.Graphics.MeasureString(tag, font); float scaleX = (float)size.Width / stringSize.Width; float scaleY = (float)size.Height / stringSize.Height; scaleX = Math.Min(1f, scaleX); scaleY = Math.Min(1f, scaleY); graphics.Graphics.ScaleTransform(scaleX, scaleY); if (size.Height > (int)stringSize.Height) { size.Height = (int)stringSize.Height; } } graphics.Graphics.DrawString(tag, font, Brushes.Black, new PointF(0, 0)); } } } if (size.Height < image.Height) { var crop = new CropCommand(LeadRect.FromLTRB(0, 0, size.Width, size.Height)); crop.Run(image); } return(image); }
public LeadRect RectToPixels(LeadRect value) { if (value.IsEmpty) { return(LeadRect.Empty); } var resolution = this.Pages.DefaultResolution; return(LeadRect.FromLTRB( DocumentToPixels(resolution, value.Left), DocumentToPixels(resolution, value.Top), DocumentToPixels(resolution, value.Right), DocumentToPixels(resolution, value.Bottom))); }
public LeadRect GetSelectedAreaRectangle(bool convertToItemCoordinates) { if (_imagePoints == null || ImageViewer == null) { return(LeadRect.Empty); } LeadRect rect = LeadRect.FromLTRB(_imagePoints[0].X, _imagePoints[0].Y, _imagePoints[4].X, _imagePoints[4].Y); if (convertToItemCoordinates) { rect = ImageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Item, rect); } return(rect); }
private void _rubberBandMode_RubberBandCompleted(object sender, ImageViewerRubberBandEventArgs e) { _frameRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadRect.FromLTRB(e.Points[0].X, e.Points[0].Y, e.Points[1].X, e.Points[1].Y)); try { if (_viewer.Image != null) { AddZones(true); _viewer.Invalidate(); UpdateMyControls(); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs e) { Graphics g = e.PaintEventArgs.Graphics; try { if (_viewer.Image != null && _ocrPage.Zones.Count > 0) { for (int i = 0; i < _ocrPage.Zones.Count; i++) { LeadRect bounds = _ocrPage.Zones[i].Bounds; LeadRect rect = LeadRect.FromLTRB(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); rect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rect); using (Pen pen = new Pen(Color.Red, 2)) { g.DrawRectangle(pen, Leadtools.Demos.Converters.ConvertRect(rect)); } } } } catch (Exception) { } }
public static LeadRect ConvertRect(Rectangle rc) { return(LeadRect.FromLTRB(rc.Left, rc.Top, rc.Right, rc.Bottom)); }
private static LeadRect ToLeadRect(PDFRect rect) { return(LeadRect.FromLTRB((int)rect.Left, (int)rect.Top, (int)rect.Right, (int)rect.Bottom)); }
public static Dictionary <int, MyWord[]> BuildWord(PDFDocument document) { Dictionary <int, MyWord[]> pageWords = new Dictionary <int, MyWord[]>(); for (int pageNumber = 1; pageNumber <= document.Pages.Count; pageNumber++) { List <MyWord> words = new List <MyWord>(); PDFDocumentPage page = document.Pages[pageNumber - 1]; IList <PDFObject> objects = page.Objects; if (objects != null && objects.Count > 0) { int objectIndex = 0; int objectCount = objects.Count; // Loop through all the objects while (objectIndex < objectCount) { // Find the total bounding rectangle, begin and end index of the next word LeadRect wordBounds = LeadRect.Empty; int firstObjectIndex = objectIndex; // Loop till we reach EndOfWord or reach the end of the objects bool more = true; while (more) { PDFObject obj = objects[objectIndex]; // Must be text and not a white character if (obj.ObjectType == PDFObjectType.Text && !Char.IsWhiteSpace(obj.Code)) { // Add the bounding rectangle of this object PDFRect temp = page.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, obj.Bounds); LeadRect objectBounds = LeadRect.FromLTRB((int)temp.Left, (int)temp.Top, (int)temp.Right, (int)temp.Bottom); if (wordBounds.IsEmpty) { wordBounds = objectBounds; } else { wordBounds = LeadRect.Union(wordBounds, objectBounds); } } else { firstObjectIndex = objectIndex + 1; } objectIndex++; more = (objectIndex < objectCount) && !obj.TextProperties.IsEndOfWord && !obj.TextProperties.IsEndOfLine; } if (firstObjectIndex == objectIndex) { continue; } // From the begin and end index, collect the characters into a string StringBuilder sb = new StringBuilder(); for (int i = firstObjectIndex; i < objectIndex; i++) { if (objects[i].ObjectType == PDFObjectType.Text) { sb.Append(objects[i].Code); } } // Add this word to the list PDFObject lastObject = objects[objectIndex - 1]; MyWord word = new MyWord(); word.Value = sb.ToString(); word.Bounds = wordBounds; word.IsEndOfLine = lastObject.TextProperties.IsEndOfLine; words.Add(word); } } // Add "IsEndOfLine" to the last word in the page, just in case it does not have it if (words.Count > 0) { MyWord word = words[words.Count - 1]; word.IsEndOfLine = true; words[words.Count - 1] = word; } pageWords.Add(pageNumber, words.ToArray()); } return(pageWords); }