Print a Real Image Size in Inches (C++ Builder)
Take the following steps to start a project and to add some code that prints an image:
1. |
Start C++ Builder. |
|
2. |
In the File menu, choose New Application. |
|
3. |
On the Builder 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. |
|
|
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. |
float fRealWidth; //Image's real width in inches
float fRealHeight;// Image's real height in inches
int XRes; // Number of pixels per logical inch along the screen width.
int YRes; // 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((int)Printer()->Canvas->Handle, 1, 1, (int)(XRes * fRealWidth), (int)(YRes * fRealHeight) ) ;
Printer()->EndDoc ();
10. |
Add #include <printers.hpp> to Unit1 header file (Unit1.h). |
11. |
Run your program to test it. |