private static void Transform(Transform transformProperties, RasterImage result) { var cropCommand = new CropCommand(); var rotateCommand = new RotateCommand { Angle = (int)(transformProperties.Rotation * 100) }; var rectCrop = new LeadRect( (int)transformProperties.Bounds.Left, (int)transformProperties.Bounds.Top, (int)transformProperties.Bounds.Width, (int)transformProperties.Bounds.Height); cropCommand.Rectangle = rectCrop; rotateCommand.Run(result); if (!transformProperties.Bounds.IsEmpty) { cropCommand.Run(result); } }
private void LoadImage(bool loadDefaultImage) { ImageFileLoader loader = new ImageFileLoader(); bool bLoaded; loader.OpenDialogInitialPath = _openInitialPath; try { loader.LoadOnlyOnePage = true; if (loadDefaultImage) { if (_ocrEngineType == OcrEngineType.Arabic) bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ArabicSample.tif", _codecs, 1, -1); else bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ocr1.tif", _codecs, 1, -1); } else bLoaded = loader.Load(this, _codecs, true) > 0; if (bLoaded) { _openInitialPath = Path.GetDirectoryName(loader.FileName); RasterImage image = loader.Image; if (image.XResolution < 150) image.XResolution = 150; if (image.YResolution < 150) image.YResolution = 150; if (_ocrPage != null) { _ocrPage.Dispose(); _ocrPage = null; } _viewer.Image = image; if (_ocrEngine.IsStarted) _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None); _currentHighlightRect = LeadRect.Empty; _recognitionResults.Text = ""; _tsMainZoomComboBox_SelectedIndexChanged(_tsMainZoomComboBox, new EventArgs()); } } catch (Exception ex) { Messager.ShowFileOpenError(this, loader.FileName, ex); } finally { _viewer.Invalidate(); } }
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 Leadtools.Forms.Ocr.OcrZone(); zone.Bounds = LogicalRectangle.FromRectangle(_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 void printDocument_PrintPage(object sender, PrintPageEventArgs e) { RasterImage image = (_imageList.ActiveItem as PDFPageItem).PageImage; // Get the print document object PrintDocument document = sender as PrintDocument; // Create an new LEADTOOLS image printer class RasterImagePrinter printer = new RasterImagePrinter(); // Set the document object so page calculations can be performed printer.PrintDocument = document; // We want to fit and center the image into the maximum print area printer.SizeMode = RasterPaintSizeMode.FitAlways; printer.HorizontalAlignMode = RasterPaintAlignMode.Center; printer.VerticalAlignMode = RasterPaintAlignMode.Center; // Account for FAX images that may have different horizontal and vertical resolution printer.UseDpi = true; // Print the whole image printer.ImageRectangle = Rectangle.Empty; // Use maximum page dimension ignoring the margins, this will be equivalant of printing // using Windows Photo Gallery printer.PageRectangle = RectangleF.Empty; printer.UseMargins = false; using (Image printImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.None)) { using (Bitmap printBitmap = new Bitmap(printImage)) { foreach (FormFieldControl control in _imageViewer.Controls) { if (control.IsFieldPrintable) { bool isFieldVisible = control.IsFieldVisible; control.IsFieldVisible = true; LeadRect leadBounds = new LeadRect(control.Bounds.X, control.Bounds.Y, control.FiedlBounds.Width, control.Bounds.Height); // convert from Control to Image coordinates leadBounds = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, leadBounds); Rectangle bounds = new Rectangle(leadBounds.X, leadBounds.Y, leadBounds.Width, leadBounds.Height); control.DrawToBitmap(printBitmap, bounds); control.IsFieldVisible = isFieldVisible; } } image = RasterImageConverter.ConvertFromImage(printBitmap, ConvertFromImageOptions.None); } } // Print the current page printer.Print(image, _currentPrintPageNumber, e); // Go to the next page _currentPrintPageNumber++; // Inform the printer whether we have more pages to print if (_currentPrintPageNumber <= document.PrinterSettings.ToPage) { e.HasMorePages = true; } else { e.HasMorePages = false; } }
protected override void OnDrawItem(DrawItemEventArgs e) { if (_sampleSymbologiesRasterImage == null) { return; } if (e.Index == -1) { return; } Rectangle rc = new Rectangle(e.Bounds.X + _delta, e.Bounds.Y + _delta, e.Bounds.Width - 10, e.Bounds.Height - _delta); if (_stringFormat == null) { _stringFormat = new StringFormat(); _stringFormat.Alignment = StringAlignment.Center; _stringFormat.LineAlignment = StringAlignment.Far; } BarcodeSymbology symbology = (BarcodeSymbology)Items[e.Index]; string name = BarcodeEngine.GetSymbologyFriendlyName(symbology); _sampleSymbologiesRasterImage.Page = (int)symbology; if (_itemPen == null) { _itemPen = new Pen(Brushes.Black, 2); } e.Graphics.DrawRectangle(_itemPen, rc); e.Graphics.FillRectangle(Brushes.White, rc); RasterPaintProperties paintProperties = RasterPaintProperties.Default; if (RasterSupport.IsLocked(RasterSupportType.Document)) { paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.Bicubic; } else { paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray; } LeadRect imageRect = new LeadRect(rc.X + 2, rc.Y + 2, rc.Width - 4, rc.Height * 2 / 3); imageRect = RasterImage.CalculatePaintModeRectangle( _sampleSymbologiesRasterImage.ImageWidth, _sampleSymbologiesRasterImage.ImageHeight, imageRect, RasterPaintSizeMode.FitAlways, RasterPaintAlignMode.CenterAlways, RasterPaintAlignMode.CenterAlways); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, rc); RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties); e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height); e.Graphics.DrawString(name, Font, SystemBrushes.HighlightText, rc, _stringFormat); } else { e.Graphics.FillRectangle(SystemBrushes.Control, rc); RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties); e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height); e.Graphics.DrawString(name, Font, SystemBrushes.ControlText, rc, _stringFormat); } }
void _viewer_MouseDown(object sender, MouseEventArgs e) { LeadPoint pixels = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y)); LeadRect imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight); if (imageBounds.Contains(pixels)) { if (e.Button == MouseButtons.Left) { double xFactor = 1; double yFactor = 1; int xOffset = 0; int yOffset = 0; Point pnt = new Point((int)Math.Ceiling(((pixels.X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((pixels.Y - yOffset) * 1.0 / yFactor + 0.5))); _movingPntIdx = -1; if (!_drawing) { Rectangle[] hyberAreas = new Rectangle[_unWarpPoints.Count]; for (int idx = 0; idx < hyberAreas.Length; idx++) { hyberAreas[idx] = CreateRectFromPoint(_unWarpPoints[idx], 20); if (hyberAreas[idx].Contains(pnt)) { _movingPntIdx = idx; break; } } } if (_movingPntIdx == -1) { if (_unWarpPoints.Count < 4) { if (pnt.Equals(_lastPoint)) { return; } _firstPointSelected = true; _unWarpPoints.Add(pnt); _currentMousePoint = pnt; UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); _lastPoint = pnt; } if (_unWarpPoints.Count == 4) { for (int ii = 1; ii <= 2; ii++) { pnt.X = (_unWarpPoints[1].X - _unWarpPoints[0].X) * ii / 3 + _unWarpPoints[0].X; pnt.Y = (_unWarpPoints[1].Y - _unWarpPoints[0].Y) * ii / 3 + _unWarpPoints[0].Y; _currentMousePoint = pnt; _unWarpPoints.Add(pnt); Invalidate(); UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); } for (int ii = 1; ii <= 2; ii++) { pnt.X = (_unWarpPoints[2].X - _unWarpPoints[3].X) * ii / 3 + _unWarpPoints[3].X; pnt.Y = (_unWarpPoints[2].Y - _unWarpPoints[3].Y) * ii / 3 + _unWarpPoints[3].Y; _unWarpPoints.Add(pnt); Invalidate(); UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); } _drawing = false; _viewer.Invalidate(); _btnApply.Enabled = true; } } } } }
public OmrBubbleLabel(string label, string value, LeadRect bounds) { this.Label = label; this.Bounds = bounds; this.Value = value; }
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); }
public DetectBarcodeOperation(RasterImage loadedImage, LeadRect lr) : base() { image = loadedImage; rect = lr; }
public static Rectangle Convert(LeadRect rc) { return(new Rectangle(rc.X, rc.Y, rc.Width, rc.Height)); }
public EmailField(string email, LeadRect bounds, EmailType type) { this.Email = email; this.Bounds = bounds; this.Type = type; }
public PhoneField(string number, LeadRect bounds, PhoneType type) { this.Number = number; this.Bounds = bounds; this.Type = type; }
public ContactField(string text, LeadRect bounds) { this.Text = text; this.Bounds = bounds; }
private void LoadImage(bool loadDefaultImage) { ImageFileLoader loader = new ImageFileLoader(); bool bLoaded; loader.OpenDialogInitialPath = _openInitialPath; try { loader.LoadOnlyOnePage = true; if (loadDefaultImage) { if (_ocrEngineType == OcrEngineType.OmniPageArabic) { bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ArabicSample.tif", _codecs, 1, -1); } else { bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ocr1.tif", _codecs, 1, -1); } } else { bLoaded = loader.Load(this, _codecs, true) > 0; } if (bLoaded) { _openInitialPath = Path.GetDirectoryName(loader.FileName); RasterImage image = loader.Image; if (image.XResolution < 150) { image.XResolution = 150; } if (image.YResolution < 150) { image.YResolution = 150; } if (_ocrPage != null) { _ocrPage.Dispose(); _ocrPage = null; } _viewer.Image = image; if (_ocrEngine.IsStarted) { _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None); } _currentHighlightRect = LeadRect.Empty; _recognitionResults.Text = ""; _tsMainZoomComboBox_SelectedIndexChanged(_tsMainZoomComboBox, new EventArgs()); } } catch (Exception ex) { Messager.ShowFileOpenError(this, loader.FileName, ex); } finally { _viewer.Invalidate(); } }