MapWinGIS:Image GetImageBitsDC
From MapWindow GIS
GetImageBitsDC
Gets the data from the image and puts it into the selected bitmap in the specified device context. This function requires the width and height of the selected bitmap and the image to match.
Note: Use of this function requires advanced knowledge in windows graphics concepts and is intended for advanced users only.
VB.NET Usage
Function GetImageBitsDC(hDC As Integer) As Boolean
Parameters
|
hDC | The handle to the device context. |
| ReturnValue | A boolean value representing the success or failure of getting the device context handle for the image. |
Sample Code
'These are API functions needed to get a device context handle and select a bitmap for the device context
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
'...
Private Sub GetImageBitsDC()
Dim hBmpPtr As IntPtr
Dim hBitmap As Integer, hndl As Integer, hDC As Integer
Dim image As New MapWinGIS.Image()
Dim success As Boolean
Dim i As Integer, j As Integer, r As Integer, g As Integer, b As Integer
Dim bitmap As System.Drawing.Bitmap
Dim result As Long
'Create a new Bitmap for the original image
bitmap = New System.Drawing.Bitmap("C:\Test.bmp")
'Get the hBitmap handle to the modified image
hBmpPtr = bitmap.GetHbitmap()
'Get an integer from the intPtr hBitmap
hBitmap = hBmpPtr.ToInt32
'Create a compatible device context handle
hDC = CreateCompatibleDC(0)
'Select the bitmap for the specified device context
result = SelectObject(hDC, hBitmap)
'Create a new MapWinGIS.Image using the width and height of the bitmap
success = image.Open("C:\Test.bmp")
'Get the image's data and put it into the selected bitmap for the specified device context
success = image.GetImageBitsDC(hDC)
'Add the image to the map
hndl = Map1.AddLayer(image, True)
End Sub
VB 6 Usage
Function GetImageBitsDC(hDC As Long) As Boolean
Parameters
|
hDC | The handle to the device context. |
| ReturnValue | A boolean value representing the success or failure of getting the device context handle for the image. |
Sample Code
'These are the API functions needed to manipulate a bitmap
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 Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
'...
Private Sub GetImageBitsDC()
Dim hBitmap As Long, hndl As Long, hDC As Long
Dim image As New MapWinGIS.image
Dim success As Boolean
Dim i As Long, j As Long
Dim bits() As Byte
Dim bm As BITMAP
'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)
'Load image from file
success = image.Open("C:\Test.bmp")
'Create a compatible device context handle
hDC = CreateCompatibleDC(0)
'Select the bitmap for the specified device context
SelectObject hDC, hBitmap
'Get the image's data and put it into the bitmap selected in the specified device context
success = image.GetImageBitsDC(hDC)
'Add the image to the map
hndl = Map1.AddLayer(image, True)
End Sub
















