MapWinGIS:Utils hBitmapToPicture
From MapWindow GIS
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
















