Error processing SSI file
LEADTOOLS Annotations (Leadtools.Annotations assembly)

Show in webframe

AnnPrinter Class






Members 
Supports printing of an Leadtools.RasterImage and a AnnContainer.
Object Model
Syntax
public class AnnPrinter : Leadtools.WinForms.RasterImagePrinter 
'Declaration
 
Public Class AnnPrinter 
   Inherits Leadtools.WinForms.RasterImagePrinter
'Usage
 
Dim instance As AnnPrinter

            

            
public ref class AnnPrinter : public Leadtools.WinForms.RasterImagePrinter 
Remarks

The AnnPrinter class derives from Leadtools.WinForms.RasterImagePrinter to make the process of printing an AnnContainer on top of an Leadtools.RasterImage easier.

Printing using the .NET framework involves adding a handler to the System.Drawing.Printing.PrintDocument.PrintPage event. In that event handler, you set up a new instance of the AnnPrinter class, set up its properties as desired, and then call the Print(RasterImage,Int32,AnnContainer,PrintPageEventArgs) method passing it the Leadtools.RasterImage to print, the image page number, the AnnContainer containing the annotation objects to be printed and the System.Drawing.Printing.PrintPageEventArgs object obtained through your System.Drawing.Printing.PrintPageEventHandler.

Example

This example loads an image, creates annotations, and prints.

Copy Code  
Imports Leadtools
Imports Leadtools.Annotations
Imports Leadtools.Codecs
Imports Leadtools.WinForms
Imports Leadtools.Drawing

Private myImage As RasterImage
Private myContainer As AnnContainer
Private Sub AnnPrinter_AnnPrinter()
   ' load an image
   Dim codecs As RasterCodecs = New RasterCodecs()
   myImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"))
   ' create a new container and add a few objects
   myContainer = New AnnContainer()
   myContainer.Bounds = New AnnRectangle(0, 0, myImage.Width, myImage.Height)

   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
   lineObj.EndPoint = New AnnPoint(200, 300, AnnUnit.Pixel)
   lineObj.Pen = New AnnPen(Color.Red, New AnnLength(4, AnnUnit.Pixel))
   myContainer.Objects.Add(lineObj)

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
   rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
   rectObj.Brush = New AnnSolidBrush(Color.Yellow)
   myContainer.Objects.Add(rectObj)

   ' intitialize a new PrintDocument object
   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 AnnPrinter = New AnnPrinter()

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

   ' 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, myContainer, e)
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Annotations;
using Leadtools.Codecs;
using Leadtools.WinForms;
using Leadtools.Drawing;

RasterImage myImage;
AnnContainer myContainer;
private void AnnPrinter_AnnPrinter()
{
   // load an image
   RasterCodecs codecs = new RasterCodecs();
   string fileName = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp");
   myImage = codecs.Load(fileName);
   // create a new container and add a few objects
   myContainer = new AnnContainer();
   myContainer.Bounds = new AnnRectangle(0, 0, myImage.Width, myImage.Height);

   AnnLineObject lineObj = new AnnLineObject();
   lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel);
   lineObj.EndPoint = new AnnPoint(200, 300, AnnUnit.Pixel);
   lineObj.Pen = new AnnPen(Color.Red, new AnnLength(4, AnnUnit.Pixel));
   myContainer.Objects.Add(lineObj);

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   rectObj.Brush = new AnnSolidBrush(Color.Yellow);
   myContainer.Objects.Add(rectObj);

   // intitialize a new PrintDocument object
   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)
{
   AnnPrinter printer = new AnnPrinter();

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

   // 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, myContainer,e);
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms

See Also

Reference

AnnPrinter Members
Leadtools.Annotations Namespace

Error processing SSI file
(Deprecated, use Leadtools.Annotations.Core instead)