Gets or sets the rectangle that specifies the portion of the image to print.
public Rectangle ImageRectangle {get; set;}Public Property ImageRectangle As RectangleA System.Drawing.Rectangle that specifies the portion of the image to print.
This rectangle must be in image coordinates. To convert between image and device coordinates refer to Leadtools.RasterImage.RectangleFromImage(Leadtools.RasterViewPerspective,Leadtools.LeadRect) and Leadtools.RasterImage.RectangleToImage(Leadtools.RasterViewPerspective,Leadtools.LeadRect)
You can also pass Rectangle.Empty to use the whole image.
This example loads an image and then prints the top-left corner of the image to the bottom-right corner of the page. For an example on printing an image using default rectangles, refer to RasterImagePrinter.
Imports Leadtools.WinFormsImports LeadtoolsImports Leadtools.Codecs' The image we are printingPrivate myRasterImage As RasterImage = NothingPublic Sub RasterImagePrinterExample2()' Check if there are printers installed on this machineIf (PrinterSettings.InstalledPrinters Is Nothing) OrElse (PrinterSettings.InstalledPrinters.Count < 1) ThenMessageBox.Show("There are no printers installed on this machine")ReturnEnd If' Load the imageUsing codecs As New RasterCodecs()Me.myRasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"))End Using' Create the print document objectUsing document As New PrintDocument()' We will use the default printer with default settings' Add handlers for Begin/Print and End print eventsAddHandler document.BeginPrint, AddressOf printDocument_BeginPrintAddHandler document.PrintPage, AddressOf printDocument_PrintPageAddHandler document.EndPrint, AddressOf printDocument_EndPrint' Use the .NET print preview dialogUsing printPreviewDlg As New PrintPreviewDialog()printPreviewDlg.Document = documentprintPreviewDlg.WindowState = FormWindowState.MaximizedprintPreviewDlg.ShowDialog()End UsingEnd Using' Clean upMe.myRasterImage.Dispose()End SubPrivate Sub printDocument_BeginPrint(ByVal sender As Object, ByVal e As PrintEventArgs)' Reset the current page number' Since we are using the print preview dialog, this event will be called twice (once' to generate the print preview and once for actual printing). So, we must set this back' to the first print page if we are going to print more than one pageEnd SubPrivate Sub printDocument_EndPrint(ByVal sender As Object, ByVal e As PrintEventArgs)' Nothing to do hereEnd SubPrivate Sub printDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)' Get the print document objectDim document As PrintDocument = DirectCast(sender, PrintDocument)' Create an new LEADTOOLS image printer classDim printer As New RasterImagePrinter()' Set the document object so page calculations can be performedprinter.PrintDocument = document' We are going to stretch the top-left corner of the image into the bottom-right corner of' the page (using the page margins)printer.SizeMode = RasterPaintSizeMode.Stretch' Align mode will not have an effect if size mode is "Stretch"printer.HorizontalAlignMode = RasterPaintAlignMode.Nearprinter.VerticalAlignMode = RasterPaintAlignMode.Near' Account for FAX images that may have different horizontal and vertical resolutionprinter.UseDpi = True' Print the top-left corner of the imageprinter.ImageRectangle = New Rectangle( _0, _0, _Me.myRasterImage.ImageWidth \ 2, _Me.myRasterImage.ImageHeight \ 2)' Use the marginsprinter.UseMargins = True' Calculate the real marginsDim xMargin As Single = e.MarginBounds.XDim yMargin As Single = e.MarginBounds.YIf Not (document.PrintController.IsPreview) Then' Real printing (Not inside a .NET PrintPreview control), get the printer hard marginsxMargin = xMargin - document.DefaultPageSettings.HardMarginXyMargin = yMargin - document.DefaultPageSettings.HardMarginY' If you want to use the page bounds instead of the margins, use this to calculate it' Dim pageBounds as RectangleF = e.PageBounds' pageBounds.Width = pageBounds.Width - document.DefaultPageSettings.HardMarginX * 2' pageBounds.Height = pageBounds.Height - document.DefaultPageSettings.HardMarginY * 2Else' If you want to use the page bounds instead of the margins, use this to calculate it' Dim pageBounds as RectangleF = e.PageBoundsEnd If' Print to the bottom right corner of the page including the marginsDim destWidth As Single = e.MarginBounds.Width \ 2Dim destHeight As Single = e.MarginBounds.Height \ 2Dim marginBounds As New RectangleF(xMargin + destWidth, yMargin + destHeight, destWidth, destHeight)printer.PageRectangle = marginBounds' Print the first current pageprinter.Print(Me.myRasterImage, 1, e)' No more pages to printe.HasMorePages = False' De-couple our PrintDocument from the RasterImagePrinterprinter.PrintDocument = NothingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools.WinForms;using Leadtools;using Leadtools.Codecs;// The image we are printingprivate RasterImage myRasterImage = null;public void RasterImagePrinterExample2(){// Check if there are printers installed on this machineif(PrinterSettings.InstalledPrinters == null || PrinterSettings.InstalledPrinters.Count < 1){MessageBox.Show("There are no printers installed on this machine");return;}// Load the imageusing(RasterCodecs codecs = new RasterCodecs()){this.myRasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"Ocr1.tif"));}// Create the print document objectusing(PrintDocument document = new PrintDocument()){// We will use the default printer with default settings// Add handlers for Begin/Print and End print eventsdocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);document.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);document.EndPrint += new PrintEventHandler(printDocument_EndPrint);// Use the .NET print preview dialogusing(PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog()){printPreviewDlg.Document = document;printPreviewDlg.WindowState = FormWindowState.Maximized;printPreviewDlg.ShowDialog();}}// Clean upthis.myRasterImage.Dispose();}private void printDocument_BeginPrint(object sender, PrintEventArgs e){// Reset the current page number// Since we are using the print preview dialog, this event will be called twice (once// to generate the print preview and once for actual printing). So, we must set this back// to the first print page if we are going to print more than one page}private void printDocument_EndPrint(object sender, PrintEventArgs e){// Nothing to do here}private void printDocument_PrintPage(object sender, PrintPageEventArgs e){// Get the print document objectPrintDocument document = sender as PrintDocument;// Create an new LEADTOOLS image printer classRasterImagePrinter printer = new RasterImagePrinter();// Set the document object so page calculations can be performedprinter.PrintDocument = document;// We are going to stretch the top-left corner of the image into the bottom-right corner of// the page (using the page margins)printer.SizeMode = RasterPaintSizeMode.Stretch;// Align mode will not have an effect if size mode is "Stretch"printer.HorizontalAlignMode = RasterPaintAlignMode.Near;printer.VerticalAlignMode = RasterPaintAlignMode.Near;// Account for FAX images that may have different horizontal and vertical resolutionprinter.UseDpi = true;// Print the top-left corner of the imageprinter.ImageRectangle = new Rectangle(0,0,this.myRasterImage.ImageWidth / 2,this.myRasterImage.ImageHeight / 2);// Use the marginsprinter.UseMargins = true;// Calculate the real marginsfloat xMargin = e.MarginBounds.X;float yMargin = e.MarginBounds.Y;if(!document.PrintController.IsPreview){// Real printing (Not inside a .NET PrintPreview control), get the printer hard marginsxMargin -= document.DefaultPageSettings.HardMarginX;yMargin -= document.DefaultPageSettings.HardMarginY;// If you want to use the page bounds instead of the margins, use this to calculate it// RectangleF pageBounds = e.PageBounds;// pageBounds.Width -= document.DefaultPageSettings.HardMarginX * 2;// pageBounds.Height -= document.DefaultPageSettings.HardMarginY * 2;}else{// If you want to use the page bounds instead of the margins, use this to calculate it// RectangleF pageBounds = e.PageBounds;}// Print to the bottom right corner of the page including the marginsfloat destWidth = e.MarginBounds.Width / 2;float destHeight = e.MarginBounds.Height / 2;RectangleF marginBounds = new RectangleF(xMargin + destWidth, yMargin + destHeight, destWidth, destHeight);printer.PageRectangle = marginBounds;// Print the first current pageprinter.Print(this.myRasterImage, 1, e);// No more pages to printe.HasMorePages = false;// De-couple our PrintDocument from the RasterImagePrinterprinter.PrintDocument = null;}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
|
Products |
Support |
Feedback: ImageRectangle Property - Leadtools.WinForms |
Introduction |
Help Version 19.0.2017.3.22
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.