MapWinGIS:Utils hBitmapToPicture

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

hBitmapToPicture

Converts an hBitmap to an IPictureDisp object..


VB.NET Usage

Function hBitmapToPicture(hBitmap As Integer) As stdole.IPictureDisp

            Parameters

hBitmap

A device context handle to a bitmap.
ReturnValue An IPictureDisp object created from the bitmap.

Sample Code

    'Use the user32 function "LoadImage" from user32.dll
        Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Integer, ByVal lpsz As String, ByVal un1 As Integer, ByVal n1 As Integer, ByVal n2 As Integer, ByVal un2 As Integer) As Integer
        '...
        Private Sub Utils_hBitmap()
        Dim hBitmap As Integer
        Dim iPictDisp As stdole.IPictureDisp
        Dim utils As New MapWinGIS.Utils()
        Dim image As New MapWinGIS.Image()
        'Constants used to get an hBitmap
        Const IMAGE_BITMAP As Integer = 0
        Const LR_LOADFROMFILE As Integer = &H10
        Const LR_CREATEDIBSECTION As Integer = &H2000
        'Load a bitmap from file storing a handle to the bitmap in hBitmap
        hBitmap = LoadImage(0, "C:\test.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
        'Get an IPictureDisp object from the hBitmap
        iPictDisp = utils.hBitmapToPicture(hBitmap)
        'Set the picture for the image to the IPictureDisp object created from the hBitmap
        image.Picture = iPictDisp
        'Add the image to the map
        Map1.AddLayer(image, True)
    End Sub
  

VB 6 Usage
Function hBitmapToPicture(hBitmap As Long) As IPictureDisp
            Parameters

hBitmap

A device context handle to a bitmap.
ReturnValue An IPictureDisp object created from the bitmap.

Sample Code

    'Use the user32 function "LoadImage" from user32.dll
        Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
        '...
    Private Sub Utils_hBitmap()
        Dim hBitmap As Long, hndl As Long
        Dim iPictDisp As IPictureDisp
        Dim utils As New MapWinGIS.utils
        Dim image As New MapWinGIS.image
        'Constants used to get an hBitmap
        Const IMAGE_BITMAP As Long = 0
        Const LR_LOADFROMFILE As Long = &H10
        Const LR_CREATEDIBSECTION As Long = &H2000
        'Load a bitmap from file storing a handle to the bitmap in hBitmap
        hBitmap = LoadImage(0, "C:\test.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
        'Get an IPictureDisp object from the hBitmap
        Set iPictDisp = utils.hBitmapToPicture(hBitmap)
        'Set the picture for the image to the IPictureDisp object created from the hBitmap
        Set image.Picture = iPictDisp
        'Add the image to the map
        hndl = Map1.AddLayer(image, True)
    End Sub

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:Utils_hBitmapToPicture"

This page has been accessed 1,495 times. This page was last modified on 9 November 2005, at 17:33.