Supports printing of an
RasterImage and a
AnnContainer.
Syntax
Visual Basic (Usage) | Copy Code |
---|
Dim instance As AnnPrinter
|
Example
This example loads an image, creates annotations, and prints.
Visual Basic | Copy Code |
---|
Private myImage As RasterImage
Private myContainer As AnnContainer
Private Sub AnnPrinter_AnnPrinter()
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
myImage = codecs.Load("C:\program files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp")
RasterCodecs.Shutdown()
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)
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
myImage.Dispose()
End Sub
Private Sub PrintDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim printer As AnnPrinter = New AnnPrinter()
printer.SizeMode = RasterPaintSizeMode.Fit
printer.HorizontalAlignMode = RasterPaintAlignMode.Center
printer.VerticalAlignMode = RasterPaintAlignMode.Center
printer.ImageRectangle = Rectangle.Empty
printer.PageRectangle = RectangleF.Empty
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 |
C# | Copy Code |
---|
RasterImage myImage; AnnContainer myContainer; private void AnnPrinter_AnnPrinter() { // load an image RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); myImage = codecs.Load(@"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp"); RasterCodecs.Shutdown(); // 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); } |
Remarks
Inheritance Hierarchy
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