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 Control to your project.

For VB4: On the Tools pull-down menu, use the Custom Controls option, and select the LEAD OLE Custom Control (16).

For VB5: On the Project pull-down menu, use the Components option, and select the LEAD Main ActiveX Control (16).

3. image\btnlead.gif Select the LEAD control; then add the control to your main form. Size and position the control as you want it to appear at run time.

4. 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's real width in inches
Dim fRealHeight As Double ' Image's 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

5. Add the following code to the main form's Load procedure to load the image:

 

LEAD1.Load "c:\image1.cmp", 0, 0, 1

6. Calculate the real width and height of the bitmap in inches. Add the following code to the main form's Load procedure:

 

fRealWidth = LEAD1.BitmapWidth / LEAD1.BitmapXRes
fRealHeight = LEAD1.BitmapHeight / LEAD1.BitmapYRes

7. Now you are ready to print the image using its real size in inches. Add the following code to the main form's Load procedure:

 

hdc = LEAD1.PrintStart

LEAD1.Render hdc, 1, 1, Printer.PrintQuality * fRealWidth, Printer.PrintQuality * fRealHeight

LEAD1.PrintEnd (hdc)

8. Run your program to test it.