(Leadtools.Controls)

フレームを表示

ImageRectangleプロパティ




印刷するためにimageの部分を指定する長方形。
構文
public Rectangle ImageRectangle {get; set;}
'Declaration
 
Public Property ImageRectangle As Rectangle

属性値

印刷するためにimageの部分を指定する長方形
解説

この長方形は、image座標でなければなりません。imageとデバイス座標の間で変換するために、RectangleFromImageRectangleToImageを参照します

全部のimageを使うために、Rectangle.Emptyを渡すこともできます。

サンプル

このサンプルはimageをロードして、それからページの右下角に、imageの左上隅を印刷します。デフォルトの長方形を使用してimageを印刷することのサンプルのために、RasterImagePrinterを参照します。

Copy Code  
Imports Leadtools
Imports Leadtools.Controls
Imports Leadtools.Codecs
Imports Leadtools.Drawing

' The image we are printing
Private myRasterImage As RasterImage = Nothing
<TestMethod>
Public Sub RasterImagePrinterExample2()
   ' Check if there are printers installed on this machine
   If PrinterSettings.InstalledPrinters Is Nothing OrElse PrinterSettings.InstalledPrinters.Count < 1 Then
      MessageBox.Show("There are no printers installed on this machine")
      Return
   End If
   ' Load the image
   Using codecs As RasterCodecs = New RasterCodecs()
      Me.myRasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"))
   End Using

   ' Create the print document object
   Using document As PrintDocument = New PrintDocument()
      ' We will use the default printer with default settings

      ' Add handlers for Begin/Print and End print events
      AddHandler document.BeginPrint, AddressOf printDocument_BeginPrint
      AddHandler document.PrintPage, AddressOf printDocument_PrintPage
      AddHandler document.EndPrint, AddressOf printDocument_EndPrint

      ' Use the .NET print preview dialog
      Using printPreviewDlg As PrintPreviewDialog = New PrintPreviewDialog()
         printPreviewDlg.Document = document
         printPreviewDlg.WindowState = FormWindowState.Maximized
         printPreviewDlg.ShowDialog()
      End Using
   End Using

   ' Clean up
   Me.myRasterImage.Dispose()
End Sub

Private 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 page
End Sub

Private Sub printDocument_EndPrint(ByVal sender As Object, ByVal e As PrintEventArgs)
   ' Nothing to do here
End Sub

Private Sub printDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
   ' Get the print document object
   Dim document As PrintDocument = TryCast(sender, PrintDocument)

   ' Create an new LEADTOOLS image printer class
   Dim printer As RasterImagePrinter = New RasterImagePrinter()

   ' Set the document object so page calculations can be performed
   printer.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 resolution
   printer.UseDpi = True

   ' Print the top-left corner of the image
   printer.ImageRectangle = New Rectangle(0, 0, Me.myRasterImage.ImageWidth \ 2, Me.myRasterImage.ImageHeight \ 2)

   ' Use the margins
   printer.UseMargins = True

   ' Calculate the real margins
   Dim xMargin As Single = e.MarginBounds.X
   Dim yMargin As Single = e.MarginBounds.Y

   If (Not document.PrintController.IsPreview) Then
      ' Real printing (Not inside a .NET PrintPreview control), get the printer hard margins
      xMargin -= 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;
   End If

   ' Print to the bottom right corner of the page including the margins
   Dim destWidth As Single = e.MarginBounds.Width \ 2
   Dim destHeight As Single = e.MarginBounds.Height \ 2
   Dim marginBounds As RectangleF = New RectangleF(xMargin + destWidth, yMargin + destHeight, destWidth, destHeight)

   printer.PageRectangle = marginBounds

   ' Print the first current page
   printer.Print(Me.myRasterImage, 1, e)

   ' No more pages to print
   e.HasMorePages = False

   ' De-couple our PrintDocument from the RasterImagePrinter
   printer.PrintDocument = Nothing
End Sub

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

// The image we are printing
private RasterImage myRasterImage = null;
[TestMethod]
public void RasterImagePrinterExample2()
{
   // Check if there are printers installed on this machine
   if (PrinterSettings.InstalledPrinters == null || PrinterSettings.InstalledPrinters.Count < 1)
   {
      MessageBox.Show("There are no printers installed on this machine");
      return;
   }
   // Load the image
   using (RasterCodecs codecs = new RasterCodecs())
   {
      this.myRasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"));
   }

   // Create the print document object
   using (PrintDocument document = new PrintDocument())
   {
      // We will use the default printer with default settings

      // Add handlers for Begin/Print and End print events
      document.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
      document.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
      document.EndPrint += new PrintEventHandler(printDocument_EndPrint);

      // Use the .NET print preview dialog
      using (PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog())
      {
         printPreviewDlg.Document = document;
         printPreviewDlg.WindowState = FormWindowState.Maximized;
         printPreviewDlg.ShowDialog();
      }
   }

   // Clean up
   this.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 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 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 resolution
   printer.UseDpi = true;

   // Print the top-left corner of the image
   printer.ImageRectangle = new Rectangle(
      0,
      0,
      this.myRasterImage.ImageWidth / 2,
      this.myRasterImage.ImageHeight / 2);

   // Use the margins
   printer.UseMargins = true;

   // Calculate the real margins
   float 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 margins
      xMargin -= 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 margins
   float 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 page
   printer.Print(this.myRasterImage, 1, e);

   // No more pages to print
   e.HasMorePages = false;

   // De-couple our PrintDocument from the RasterImagePrinter
   printer.PrintDocument = null;
}

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

ターゲットプラットホーム

参照

参照

RasterImagePrinterクラス
RasterImagePrinterメンバ