MapWinGIS:SampleCode-VB Net:APIBitBlast

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

Obtain a Snapshot using API Bit Blast

If you are drawing items on top of the control, or simply can't work with the VB6 Image format, this function allows you to create a Snapshot of the control. Make sure that you take the snapshot before you raise any dialog windows, though or you will accidentally capture the dialog in the snapshot.

     'Declare area 
     <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> Private Shared Function BitBlt( _
     ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, _
     ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean
     End Function
     ' 
     'The Older Declare format also works: 
     'Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean 
 
     Private Sub mnuExportMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExportMap.Click
         Dim g1 As Graphics = AxMap1.CreateGraphics()
         Dim MyImage As Image = New Bitmap(AxMap1.ClientRectangle.Width, AxMap1.ClientRectangle.Height, g1)
         Dim g2 As Graphics = Graphics.FromImage(MyImage)
         Dim dc1 As IntPtr = g1.GetHdc()
         Dim dc2 As IntPtr = g2.GetHdc()
         Dim sf As New SaveFileDialog
         Dim fmt As Imaging.ImageFormat
         Dim ext As String
 
         'Old API BitBlast
         BitBlt(dc2, 0, 0, AxMap1.ClientRectangle.Width, AxMap1.ClientRectangle.Height, dc1, 0, 0, 13369376)
         g1.ReleaseHdc(dc1)
         g2.ReleaseHdc(dc2)
         sf.Filter = "Bitmap Format (*.bmp)|*.bmp|Emf Format (*.emf)|*.emf|Exif Format (*.exf)|*.exf|Gif Format (*.gif)|*.gif|Icon Format (*.Ico)|*.Ico|JPeg Format (*.jpg)|*.jpg|Png Format (*.png)|*.png|Tiff Format (*.tif)|*.tif|Wmf Format (*.wmf)|*.wmf"
         If Not sf.ShowDialog(Me) = DialogResult.OK Then Exit Sub
         ext = System.IO.Path.GetExtension(sf.FileName)
         Select Case ext
             Case ".bmp" : fmt = Imaging.ImageFormat.Bmp
             Case ".emf" : fmt = Imaging.ImageFormat.Emf
             Case ".exf" : fmt = Imaging.ImageFormat.Exif
             Case ".gif" : fmt = Imaging.ImageFormat.Gif
             Case ".ico" : fmt = Imaging.ImageFormat.Icon
             Case ".jpg" : fmt = Imaging.ImageFormat.Jpeg
             Case ".png" : fmt = Imaging.ImageFormat.Png
             Case ".tif" : fmt = Imaging.ImageFormat.Tiff
             Case ".wmf" : fmt = Imaging.ImageFormat.Wmf
             Case Else : fmt = Imaging.ImageFormat.Bmp
         End Select
         MyImage.Save(sf.FileName, fmt)
     End Sub
 

posted by Shade1974 on 12/9/2005

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-VB_Net:APIBitBlast"

This page has been accessed 2,629 times. This page was last modified on 9 December 2005, at 18:53.