Print a Real Image Size in Inches (C++ Builder 6.0)
Take the following steps to start a project and to add some code that prints an image:
1. |
Start C++ Builder 6. |
|
2. |
If you didn’t install LEAD RasterView Control, install it as follows: |
|
|
On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD RasterView Control (14.5). Press Install, and then compile and install the package dclusr40.bpk. |
|
3. |
Select the LEAD RasterView control and add it to your form. Size and position the control, as you want it to appear at run time. |
|
4. |
If you didn’t import LEAD Raster IO before, import it as follows: |
|
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO Object Library (14.5). Press install, and then compile and install the package dclusr.bpk. |
|
5. |
From the ActiveX controls tab, add the LEAD Raster IO to your form. |
|
6. |
Add a button control to your form and name it as follows: |
|
|
Name |
Caption |
|
btnPrint |
|
7. |
Declare the following variables in the private section of “Unit1.h”. |
float fRealWidth; //Image real width in inches
float fRealHeight;// Image 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.
8. |
Handle the btnPrint button's click procedure and code the btnPrintClick procedure as follows. This code loads an image. |
void __fastcall TForm1::btnPrintClick(TObject *Sender)
{
LEADRasterIO1->Load ( LEADRasterView1->Raster, AnsiToOLESTR ("c:\\image1.cmp"), 0, 0, 1 );
}
9. |
You should now calculate the real width and height of the bitmap in inches. Add the following code to btnPrintClick procedure: |
fRealWidth= LEADRasterView1->Raster->BitmapWidth / LEADRasterView1->Raster->BitmapXRes;
fRealHeight= LEADRasterView1->Raster->BitmapHeight / LEADRasterView1->Raster->BitmapYRes;
10. |
Now you are ready to print the image with real size in inches. Add the following code to btnPrintClick procedure: |
LEADRasterView1->Render ((int)Printer()->Canvas->Handle,
1,
1,
(int)(XRes * fRealWidth),
(int)(YRes * fRealHeight) ) ;
Printer()->EndDoc ( );
11. |
Include the following file in “Unit1.h” |
#include <printers.hpp>
12. |
Run your program to test it. |