UseDpi Property

Summary

Gets or sets a value that indicates whether LEAD's automated scaling properties are used to account for the physical resolution of the image when printing FAX images.

Syntax

C#
C++/CLI
C++
public bool UseDpi { get; set; } 
public: 
property bool UseDpi { 
   bool get(); 
   void set (    bool ); 
} 
public:  
   property bool UseDpi 
   { 
      bool get() 
      void set(bool value) 
   } 

Property Value

true Account for the physical resolution. Default value is true.

Remarks

The physical resolution of an image is measured in dots per inch (DPI). When you load an image, the Leadtools.RasterImage.XResolution and Leadtools.RasterImage.YResolution properties are updated with the DPI values for the horizontal and vertical resolution. Some images have different horizontal and vertical resolutions. For example, the horizontal resolution of a fax image is typically twice its vertical resolution (for example 200 by 100). In such cases, the displayed images will appear elongated if you do not account for the resolution.

If the values of the Leadtools.RasterImage.XResolution property and the Leadtools.RasterImage.YResolution property are not equal, set the UseDpi property to true to have LEAD's automated scaling properties account for the physical resolution of the Leadtools.RasterImage when printed using Print

Example

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
 
// The image we are printing 
private RasterImage myImage = null; 
// The current page number being printed 
private int currentPrintPageNumber; 
 
public void RasterImagePrinterExample() 
{ 
   // 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.myImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")); 
   } 
 
   // Create the print document object 
   using (PrintDocument document = new PrintDocument()) 
   { 
      // Setup the document pages 
      document.PrinterSettings.MinimumPage = 1; 
      document.PrinterSettings.MaximumPage = this.myImage.PageCount; 
      document.PrinterSettings.FromPage = 1; 
      document.PrinterSettings.ToPage = this.myImage.PageCount; 
 
      DialogResult result = DialogResult.OK; 
 
      // Select the printer 
      using (PrintDialog printDlg = new PrintDialog()) 
      { 
         printDlg.Document = document; 
 
         printDlg.AllowSomePages = true; 
 
         result = printDlg.ShowDialog(); 
      } 
 
      // Setup the page 
      if (result == DialogResult.OK) 
      { 
         using (PageSetupDialog pageSetupDlg = new PageSetupDialog()) 
         { 
            pageSetupDlg.Document = document; 
            pageSetupDlg.ShowDialog(); 
         } 
      } 
 
      if (result == DialogResult.OK) 
      { 
         // Add handlers for Begin/Print and End print events 
         document.BeginPrint += new PrintEventHandler(document_BeginPrint); 
         document.PrintPage += new PrintPageEventHandler(document_PrintPage); 
         document.EndPrint += new PrintEventHandler(document_EndPrint); 
 
         // Use the .NET print preview dialog 
         using (PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog()) 
         { 
            printPreviewDlg.Document = document; 
            printPreviewDlg.WindowState = FormWindowState.Maximized; 
            result = printPreviewDlg.ShowDialog(); 
         } 
      } 
   } 
 
   // Clean up 
   this.myImage.Dispose(); 
} 
 
private void document_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 
   PrintDocument document = sender as PrintDocument; 
   this.currentPrintPageNumber = document.PrinterSettings.FromPage; 
} 
 
private void document_EndPrint(object sender, PrintEventArgs e) 
{ 
   // Nothing to do here 
} 
 
private void document_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 want to fit and center the image into the maximum print area 
   printer.SizeMode = RasterPaintSizeMode.FitAlways; 
   printer.HorizontalAlignMode = RasterPaintAlignMode.Center; 
   printer.VerticalAlignMode = RasterPaintAlignMode.Center; 
 
   // Account for FAX images that may have different horizontal and vertical resolution 
   printer.UseDpi = true; 
 
   // Print the whole image 
   printer.ImageRectangle = Rectangle.Empty; 
 
   // Use maximum page dimension ignoring the margins, this will be equivalant of printing 
   // using Windows Photo Gallery 
   printer.PageRectangle = RectangleF.Empty; 
   printer.UseMargins = false; 
 
   // Print the current page 
   printer.Print(this.myImage, this.currentPrintPageNumber, e); 
 
   // Go to the next page 
   this.currentPrintPageNumber++; 
 
   // Inform the printer whether we have more pages to print 
   if (this.currentPrintPageNumber <= document.PrinterSettings.ToPage) 
      e.HasMorePages = true; 
   else 
      e.HasMorePages = false; 
 
   // De-couple our PrintDocument from the RasterImagePrinter 
   printer.PrintDocument = null; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Reference

RasterImagePrinter Class

RasterImagePrinter Members

Help Version 22.0.2023.1.24
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.