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

Glossary Item Box

Description

Prints the current image to the printer.

Syntax

Visual Basic
Public Sub PrintImage() 

Remarks

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.

Example

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

Type RECT
    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
    Else
        xRes = 300
    End If

    If ImageControl1.ImageYRes <> 0 Then
        yRes = ImageControl1.ImageYRes
    Else
        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
    Else
        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

    ImageControl1.PrintImage

    ImageControl1.PrintEndDoc

    ' Restore the Cursor

    MousePointer = 0

End Sub

See Also

© 2014 Data Techniques Inc. All Rights Reserved.