MapWindow Home
Search MapWindow.org


  • Home
    • Download
    • Why MW
    • FAQ
    • Contact
  • Products
    • MapWindow
    • ActiveX
    • Plug-ins
  • Software Dev
    • Sample Code
    • Scripts
    • Source
    • Bugs
    • Support
    • Languages
  • Site Tools
    • Forums
    • Tutorials
    • Mailing Lists
    • Team
    • Site Stats
    • Links
  • Get Stuff
    • Buy a CD
    • Buy a T-Shirt
    • MW Book
    • ActiveX Book
    • Donate
    • Buy Support
  • Documentation
    • MWGIS App. User Guide
    • GISTools User Guide
    • MW Plug-ins Dev. Guide
    • MWGIS ActiveX Dev. Guide
    • MWGeoProc Dev. Guide

MapWinGIS:Image GetImageBitsDC

From MapWindow GIS

Jump to: navigation, search

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

Retrieved from "http://www.mapwindow.org/wiki/index.php/MapWinGIS:Image_GetImageBitsDC"
Views
  • Page
  • Discussion
  • View source
  • History
Personal tools
  • Log in / create account
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link

Geospatial Software Lab

Copyright © 2008 - MapWindow Open Source Team
( last updated: December 03 2008.)
Home | Donate | Download | MapWindow GIS Desktop | MapWinGIS.ocx | Plug-ins | Contact | Lists | Bugs | Sample Code | Documentation
Code Repository | Open Source License | Discussion Forum | Wiki | Join the Team | Site Statistics | Links