ImageMan ActiveX Control Version 8
PrintImage Method
See Also  Example  Send comments on this topic.

Glossary Item Box


Prints the current image to the printer.


Visual Basic
Public Sub PrintImage() 


Invoking this method causes the image to be printed in the bounding box specified by DstLeft, DstTop, DstRight, and DstBottom. Before invoking this method you must set the PrnHdc, DstLeft, DstTop, DstRight and DstBottom properties.

To print only a portion of the image you must also set the SrcLeft, SrcTop, SrcRight, and SrcBottom properties.


Print Best Fit (Visual Basic)Copy Code
' Declare API functions at the module level

    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Declare Function GetClipBox Lib "gdi32" (ByVal hDC As Long, lpRect As RECT) As Long

. . .

Private Sub PrintImageBestFit()

    ' Print an Image at best fit while maintaining aspect ratio

    Dim nPageXMid As Long, nPageYMid As Long
    Dim ImgWidth As Long, ImgHeight As Long
    Dim nWidth As Long, nHeight As Long
    Dim xMag As Double, yMag As Double
    Dim xRes As Integer, yRes As Integer
    Dim rPrinter As RECT
    Dim lRet As Long

    ' Initialize the ImageMan printing mechanism
    ImageControl1.PrintStart False

    lRet = GetClipBox(ImageControl1.PrnHdc, rPrinter)

    ' Get the image resolution - If not specified default to 300 dpi
    If ImageControl1.ImageXRes <> 0 Then
        xRes = ImageControl1.ImageXRes
        xRes = 300
    End If

    If ImageControl1.ImageYRes <> 0 Then
        yRes = ImageControl1.ImageYRes
        yRes = 300
    End If

    ' Calculate the Image size in TWIPS

    ImgWidth = ImageControl1.ImageWidth * 1440 / xRes
    ImgHeight = ImageControl1.ImageHeight * 1440 / yRes

    ' Calculate the center of the page
    nPageXMid = (rPrinter.Right - rPrinter.Left) / 2
    nPageYMid = (Abs(rPrinter.Bottom - rPrinter.Top)) / 2

    xMag = (rPrinter.Right - rPrinter.Left) / ImgWidth
    yMag = (Abs(rPrinter.Bottom - rPrinter.Top)) / ImgHeight

    If xMag > yMag Then
        nWidth = ImgWidth * yMag
        nHeight = ImgHeight * yMag
        nWidth = ImgWidth * xMag
        nHeight = ImgHeight * xMag
    End If

    ' Tell the control where to print the size

    ImageControl1.DstLeft = nPageXMid - nWidth / 2
    ImageControl1.DstTop = nPageYMid - nHeight / 2
    ImageControl1.DstRight = nPageXMid + nWidth / 2
    ImageControl1.DstBottom = nPageYMid + nHeight / 2

    ' Set the Hourglass Cursor, this may take a few seconds
    MousePointer = 11



    ' Restore the Cursor

    MousePointer = 0

End Sub

See Also

© 2014 Data Techniques Inc. All Rights Reserved.