Print a Real Image Size in Inches (Visual Basic)
Take the following steps to start a project and to add some code that prints an image:
1. |
Start Visual Basic. |
2. |
Add the LEAD RasterView Control to your project. |
|
On the Project pull-down menu, use the Components option, and select the LEAD RasterView Control (14.5). |
3. |
Add the LEAD RasterIO Object Library and LEAD Raster Variant Object Library to your project. |
|
On the Project pull-down menu, use the References option, and select the LEAD RasterIO Object Library (14.5). |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5). |
4. |
Select the LEAD RasterView control; then add the control to your main form. Size and position the control as you want it to appear at run time. |
5. |
Add the following variables to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code. |
Dim fRealWidth As Double ' Image real width in inches
Dim fRealHeight As Double ' Image real height in inches
Dim fPrnDPIX As Double ' Number of pixels per logical inch along the screen width
Dim fPrnDPIY As Double ' Number of pixels per logical inch along the screen height
Dim hdc As Long
Dim LEADRstIO As New LEADRasterIO
6. |
Add the following code to the main form's Load procedure to load the image. Suppose to you have an image somewhere, then load it: |
LEADRstIO.Load LEADRasterView1.Raster, "c:\image1.cmp", 0, 0, 1
7. |
You should now calculate the real width and height of the bitmap in inches. Add the following code to the main form's Load procedure: |
fRealWidth = LEADRasterView1.Raster.BitmapWidth / LEADRasterView1.Raster.BitmapXRes
fRealHeight = LEADRasterView1.Raster.BitmapHeight / LEADRasterView1.Raster.BitmapYRes
8. |
Now you are ready to print the image with real size in inches. Add the following code to the main form's Load procedure: |
hdc = LEADRasterView1.PrintStart
LEADRasterView1.Render hdc, 1, 1, Printer.PrintQuality * fRealWidth, Printer.PrintQuality * fRealHeight
LEADRasterView1.PrintEnd (hdc)
9. |
Run your program to test it. |
10. |
Save the project be used as a starting point for other tasks in this tutorial. |