IC Imaging Control ActiveX

OverlayBitmap.GetDC Method

OverlayBitmap.GetDC Method

This method returns the device context of the OverlayBitmap object.
Syntax:

Public Function GetDC() As Long
Return Value:

A long value that contains the handle to the device context that is used in the OverlayBitmap. If an error occurs, the returned value is zero.

Limitations:

Run time only. Only after ICImagingControl.LiveStart has been called once.

Remarks:

If the returned device context is no longer used, an application must call OverlayBitmap.ReleaseDC to release the device context.

Example:

This Basic example demonstrates how to place a bitmap on the live video.

'
' ShowBitmap
'
' This sub demonstrates how to use OverlayBitmap.GetDC to blit a bitmap
' from a file on the live video.
' The bitmap will be blitted with transparency on the live video because
' it's background color is magenta (load the image "Hardware.png"
' with "Paint.exe" to verify this). Magenta is the currently set
' dropout color. The used GDI graphic functions are based on pixel units.
' Therefore, the scaling functions of Visual Basic are called to get the
' size of the loaded bitmap in pixels.
'
Private Sub ShowBitmap(ob As OverlayBitmap)
    Dim Pic As New StdPicture
    Dim PicWidth As Integer
    Dim PicHeight As Integer
    Dim obDC As Long
    Dim SourceDC As Long
    Dim Col As Integer

    ' Load a BMP file.
    Set Pic = LoadPicture(App.Path & "\hardware.png")

    ' Transform the size of the picture from himetric to pixel units.
    PicWidth = ScaleX(Pic.Width, vbHimetric, vbPixels)
    PicHeight = ScaleX(Pic.Height, vbHimetric, vbPixels)

    ' Calculate a column to display the bitmap in the
    ' upper right corner of Imaging Control.
    Col = ICImagingControl1.Width - 5 - PicWidth

    ' Get the DC of the OverlayBitmap object.
    obDC = ob.GetDC
    If obDC <> 0 Then
        ' Create a compatible DC that is used to hold the loaded bitmap.
        SourceDC = CreateCompatibleDC(obDC)
        If SourceDC <> 0 Then
            ' Select the loaded bitmap in the source DC.
            SelectObject SourceDC, Pic.handle

            ' Now blit the source DC in the overlay bitmap DC.
            ' This copies the loaded bitmap to the overlay bitmap.
            BitBlt obDC, Col, 5, PicWidth, PicHeight, _
                    SourceDC, 0, 0, 13369376  ' 13369376 is SRCCOPY

            ' Delete the DC source that is no longer needed to avoid handle leaks.
            DeleteDC SourceDC
        End If

        ' Release the DC.
        ob.ReleaseDC obDC
    End If
End Sub

The example uses functions from the Windows GDI library. They must be declared on top the form as follows.

' The GDI (graphics device interface) functions
' must be declared before they can be used.
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" _
                          (ByVal handle As Long) As Long

Private Declare Function DeleteDC Lib "gdi32.dll" _
                          (ByVal handle As Long) As Long

Private Declare Function SelectObject Lib "gdi32.dll" _
                          (ByVal DC As Long, ByVal HGDIObj As Long) As Long

Private Declare Function BitBlt Lib "gdi32.dll" ( _
                              ByVal hdcDest As Long, _
                              ByVal nXDest As Long, _
                              ByVal nYDest As Long, _
                              ByVal nWidth As Long, _
                              ByVal nHeight As Long, _
                              ByVal hdcSrc As Long, _
                              ByVal nXSrc As Long, _
                              ByVal nYSrc As Long, _
                              ByVal dwRop As Long _
                              ) As Boolean
See also: OverlayBitmap, OverlayBitmap.ReleaseDC, ICImagingControl.LiveStart

<< ICImagingControl.OverlayBitmap

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us