Leadtools.WinForms Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.8.31
RasterImagePrinter Class
See Also  Members   Example 
Leadtools.WinForms Namespace : RasterImagePrinter Class




Supports printing of an RasterImage

Syntax

Visual Basic (Declaration) 
Public Class RasterImagePrinter 
Visual Basic (Usage)Copy Code
Dim instance As RasterImagePrinter
C# 
public class RasterImagePrinter 
Managed Extensions for C++ 
public __gc class RasterImagePrinter 
C++/CLI 
public ref class RasterImagePrinter 

Example

This example loads an image and then sends it to the printer.

Visual BasicCopy Code
Public myImage As RasterImage = Nothing
Public Sub RasterImagePrinter_RasterImagePrinter()
   ' load an image
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   myImage = codecs.Load("C:\program files\LEAD Technologies\LEADTOOLS 15\Images\clean.tif")
   RasterCodecs.Shutdown()

   If Not PrinterSettings.InstalledPrinters Is Nothing AndAlso PrinterSettings.InstalledPrinters.Count > 0 Then
      Dim printDocument As PrintDocument = New PrintDocument()
      AddHandler printDocument.PrintPage, AddressOf printDocument_PrintPage
      printDocument.Print()
   End If

   ' dispose the image
   myImage.Dispose()
End Sub

Private Sub printDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
   Dim printer As RasterImagePrinter = New RasterImagePrinter()

   ' We want normal size (not zoomed) but centered
   printer.SizeMode = RasterPaintSizeMode.Fit
   printer.HorizontalAlignMode = RasterPaintAlignMode.Center
   printer.VerticalAlignMode = RasterPaintAlignMode.Center

   ' Account for image resolution
   printer.UseDpi = True

   ' print the whole image
   printer.ImageRectangle = Rectangle.Empty

   ' use maximum page
   printer.PageRectangle = RectangleF.Empty

   ' Win32 GDI printing and scale to gray
   Dim props As RasterPaintProperties = RasterPaintProperties.Default
   props.PaintEngine = RasterPaintEngine.Gdi
   props.PaintDisplayMode = props.PaintDisplayMode Or RasterPaintDisplayModeFlags.ScaleToGray
   printer.PaintProperties = props
   printer.Print(myImage, myImage.Page, e)
End Sub
C#Copy Code
public RasterImage myImage = null; 
public void RasterImagePrinter_RasterImagePrinter() 

   // load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   myImage = codecs.Load(@"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\clean.tif"); 
   RasterCodecs.Shutdown(); 
 
   if(PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) 
   { 
      PrintDocument printDocument = new PrintDocument(); 
      printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); 
      printDocument.Print(); 
   } 
 
   // dispose the image 
   myImage.Dispose(); 

 
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) 

   RasterImagePrinter printer = new RasterImagePrinter(); 
 
   // We want normal size (not zoomed) but centered 
   printer.SizeMode = RasterPaintSizeMode.Fit; 
   printer.HorizontalAlignMode = RasterPaintAlignMode.Center; 
   printer.VerticalAlignMode = RasterPaintAlignMode.Center; 
 
   // Account for image resolution 
   printer.UseDpi = true; 
 
   // print the whole image 
   printer.ImageRectangle = Rectangle.Empty; 
 
   // use maximum page 
   printer.PageRectangle = RectangleF.Empty; 
 
   // Win32 GDI printing and scale to gray 
   RasterPaintProperties props = RasterPaintProperties.Default; 
   props.PaintEngine = RasterPaintEngine.Gdi; 
   props.PaintDisplayMode |= RasterPaintDisplayModeFlags.ScaleToGray; 
   printer.PaintProperties = props; 
   printer.Print(myImage, myImage.Page, e); 
}

Remarks

The RasterImagePrinter provides properties and method to make the process of printing an RasterImage easier.

Printing using the .NET framework involves adding a handler to the PrintPage event. In that event handler, you setup a new instance of the RasterImagePrinter class, setup its properties as desired then call the Print method passing it the RasterImage to print, the page number to print and the PrintPageEventArgs object obtained through your PrintPageEventHandler.

Note: The RasterViewerCenterMode type has been renamed in version 15. Use the RasterPaintAlignMode enumeration instead.

Inheritance Hierarchy

System.Object
   Leadtools.WinForms.RasterImagePrinter

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also