Print a Real Image Size in Inches (Delphi 4)
Take the following steps to start a project and to add some code that prints an image:
1. |
Start Delphi. |
|
2. |
In the File menu, choose New Application. |
|
3. |
On the Delphi toolbar, click the LEADTOOLS tab. If you have used a LEAD VCL control before, the icon appears on the toolbar. Otherwise, refer to Installing VCL before continuing with this tutorial. |
|
4. |
Select the LEAD Main control on the VCL toolbar. Size and position the control, as you want it to appear at run time. |
|
5. |
Add a button control to your form and name it as follows: |
|
|
Name |
Caption |
|
btnPrint |
|
6. |
Declare the following variables in the private section of Form1. |
fRealWidth: Single; //Image's real width in inches
fRealHeight: Single;// Image's real height in inches
XRes: Integer; // Number of pixels per logical inch along the screen width.
YRes: Integer; // Number of pixels per logical inch along the screen Height.
7. |
Handle the btnPrint button's click procedure and add the following code to it to load the image.: |
LEADImage1.Load('c:\image1.cmp', 0, 0, 1);
8. |
Calculate the real width and height of the bitmap in inches. Add the following code to btnPrintClick procedure: |
fRealWidth:= LEADImage1.BitmapWidth / LEADImage1.BitmapXres;
fRealHeight:= LEADImage1.BitmapHeight / LEADImage1.BitmapYRes;
9. |
Print the image using its real size in inches. Add the following code to btnPrintClick procedure: |
Printer.BeginDoc ( ) ;
//You should have the number of pixels per logical inch (XRes, YRes)
XRes:= GetDeviceCaps ( Printer.Canvas.Handle, LOGPIXELSX ) ;
YRes:= GetDeviceCaps ( Printer.Canvas.Handle, LOGPIXELSY ) ;
LEADImage1.Render( Printer.Canvas.Handle, 1, 1, Trunc(XRes * fRealWidth), Trunc(YRes * fRealHeight) ) ;
Printer.EndDoc;
10. |
Add Printers to the Uses section of the Uint1. |
11. |
Run your program to test it. |