This project is read-only.

Beginners question: how to make a snapshot sended to file

Sep 4, 2012 at 10:14 PM

I was wondering how to code a working snapshot from  the map when pressing a button....

I have found the function snapshot but can not find any working code ...

Anyone have some working VB code that could give this beginner some direction?



This is code that I used in an other MAPWINGIS project

    Private Sub btnTakeSnapshot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTakeSnapshot.Click
        Dim Image As New MapWinGIS.Image()
        Dim extents As Extents
        Dim strFilenaam As String = Format(Now, "dd-MM-yyyy_hh-mm-ss")
        strFilenaam = SelecteerSubDir(strFilenaam)
        If strFilenaam <> "" Then
            'Set extents to be the extents of the map
            extents = CType(MapMain.Extents, Extents)
            'Take a picture of what is being displayed in map and store it in image
            Image = MapMain.SnapShot(extents)
            Image.Save(strFilenaam, True, ImageType.USE_FILE_EXTENSION)
        End If
    End Sub

Sep 8, 2012 at 12:04 AM
Edited Sep 8, 2012 at 12:05 AM

Here the solution, this one saves it to clipboard

    Private Sub btnSaveVenster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClipVenster.Click
    End Sub

And this to save a file.... with a prefix and date and time stamp....

    Private Sub btnSaveSnapshot_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSnapshot.Click
        If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
            Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
            Dim strFilenaamPrefix As String = txtPadFileNaam.Text
            Dim strFilenaamExtensie As String = Format(Now, "dd-MM-yyyy_hh-mm-ss")
            Dim strFilenaamTotaalBITMAP As String = strFilenaamPrefix & "_DMCviewer_" & strFilenaamExtensie & ".bmp"
            Dim strFilenaamTotaalJPG As String = strFilenaamPrefix & "_DMCviewer_" & strFilenaamExtensie & ".jpeg"
            Dim strFilenaamTotaalGIF As String = strFilenaamPrefix & "_DMCviewer_" & strFilenaamExtensie & ".gif"

            If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
                Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
                'To Save as Bitmap
                oImgObj.Save(strFilenaamTotaalBITMAP, System.Drawing.Imaging.ImageFormat.Bmp)
                'To Save as Jpeg
                oImgObj.Save(strFilenaamTotaalJPG, System.Drawing.Imaging.ImageFormat.Jpeg)
                'To Save as Gif
                oImgObj.Save(strFilenaamTotaalGIF, System.Drawing.Imaging.ImageFormat.Gif)
            End If
        End If
    End Sub