V-Basic, Defining Snapshot Extents with drawing tool and Zoom

Dirty Visual Basic “programmer” here ( and I use that term loosely) and I am stumbling a bit on a portion of code for a project I’m currently working on.

Right now, I have the below code deployed for which a user can grab a basic screengrab of whatever is in the AXMAP1 window. if you can see it, it grabs it AND at whatever the current Zoom Level is. This is alright, but it seems a bit lacking, especially if the chart / map is large. Now the user has to decide to grab everything in one image, with little definition, or zoom in and take a bunch of screen grabs and then stitch them together in post (not ideal).

The code I currently have implemented is:

Private Sub Label2_DoubleClick(sender As Object, e As EventArgs) Handles Label2.DoubleClick
    Dim ScreenGrab As New MapWinGIS.Image()
    Dim ScreenExtents As MapWinGIS.Extents
    Dim success As Boolean
    Dim Filename As String
    ScreenExtents = CType(AxMap1.Extents, MapWinGIS.Extents)
    Filename = "C:\sitepad\" & mMapFile & "-" & ScreenGrabCount & "-" & DateString & ".jpg"
    ScreenGrab = AxMap1.SnapShot(ScreenExtents)
    success = ScreenGrab.Save(Filename, False, MapWinGIS.ImageType.JPEG_FILE)
    If Not success Then
        MsgBox("There were errors saving the image")
    Else
        ScreenGrabCount = ScreenGrabCount + 1
    End If
End Sub

As a temp solution, i have a label being used as a double-clickable button. I create a new image names “Screengrab” and set the extents. naming convention allows me to save the image in my primary directory, with the map name, a screengrab counter number and the current date. Not really important.

What I would like to try is to allow the user to draw a rectangle around the area of the map they would like a screengrab. Then the user can zoom in or out accordingly with the rectangle growing or shrinking accordingly. Then the user takes the snapshot and the image saved. So I just need some direction on how to draw the rectangle, and how to use that rectangle to set the Extents. I think once that’s done, the zoom layer will just take care of itself, unless there is a better way to handle that.

Any insight will be greatly appreciated. I am using MapWinGis 4.95.

Regards,
Eric

Adding to this in the hopes somebody can help me.

I now have code that allows the user to select an area of the chart with the CMSelection tool. This provides the pixel locations of the bottom left corner and the top right corner, which I then use the pixeltoproj methods to work out the coordinates of those locations. I can then save just that location.

Private Sub AxMap1_SelectBoxFinal(sender As Object, e As _DMapEvents_SelectBoxFinalEvent) Handles AxMap1.SelectBoxFinal
    Dim ScreenGrab2 As New MapWinGIS.Image()
    Dim pxMin, pxMax, pyMin, pyMax As Double
    Dim myExtents As New MapWinGIS.Extents()
    Dim filename As String
    Dim success As Boolean

    AxMap1.PixelToProj(e.left, e.bottom, pxMin, pyMin)
    AxMap1.PixelToProj(e.right, e.top, pxMax, pyMax)
    myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0)



    filename = "C:\sitepad\" & mMapFile & "-" & ScreenGrabCount & "-" & DateString & ".jpg"
    ScreenGrab2 = AxMap1.SnapShot(myExtents)


    If MsgBox("Save selected Area as JPG", 1, "Image Capture") = vbCancel Then
        'user hit cancel
        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan
        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault
    Else
        'user hit save
        ScreenGrabCount = ScreenGrabCount + 1
        success = ScreenGrab2.Save(filename, False, MapWinGIS.ImageType.JPEG_FILE)

        If Not success Then
            MsgBox("There were errors saving the image")
        Else
            AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan
            AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault
        End If
    End If



    System.Diagnostics.Debug.WriteLine("Bottom left corner: " & pxMin & "-" & pyMin)
    System.Diagnostics.Debug.WriteLine("Top Right corner: " & pxMax & "-" & pyMax)



End Sub

This works, and makes an image of whatever the user selects, at whatever zoom level is currently being observed by the user on the screen. It would seem, however that if i make the selection, and save those coordinates of the desired area as the extents, and then zoom in, for more detail and then save the image, that the image reverts to whatever the zoom was when the selection was made. It is baffling me. Is there a way, once the selection as been made, to change the zoom level or scale of the image so the desired area is saved as an image, but at the higher zoom level?

Also, When I track what the axmap1.currentzoom is, it will never let me get past 20, even if i zoom in more, it seems to be unable to track past 20. though if I manually set something beyond 20, it zooms in to what i would believe to be that level. Any thoughts on this?

Snapshot Method - returns an image with size 959x514 no matter what size the selection box is or the current zoom level. Any ideas?

I just wanted to update this Thread.

Basically, I let the user draw a selection box and save those boundaries. The user can then zoom in or out and the code recalculates the new boundaries and pixel width. its as simple as that. Hopefully this helps someone out down the road…you know, if somebody is also using visual basic.

    Dim newLeft, newRight, newUp, newDown As Double
    Dim newPXMAX, newPXMIN, newPYMAX, newPYMIN As Double
    Dim newPwidth As Double
    Dim absoluteLeft
    Dim Filename1 As String
    Dim newsuccess As Boolean
    Dim newimage As MapWinGIS.Image
    Dim time As String
    time = Format(Now, "hh-mm-ss")

    Filename1 = "C:\sitepad\images\" & mMapFile & "_" & time & "_" & DateString & ".jpg"   'defines the filename and location

    AxMap1.ProjToPixel(pxMin, pyMin, newLeft, newDown)  'The user uses a selection box as the first step
    AxMap1.ProjToPixel(pxMax, pyMax, newRight, newUp)   'Then the user can zoom in and out as desired. this block tracks the new bounds of that original selection
    AxMap1.PixelToProj(newLeft, newDown, newPXMIN, newPYMIN)    'Once the user is happy, they hit the save icon, the new bounderies are converted back to coordinates,
    AxMap1.PixelToProj(newRight, newUp, newPXMAX, newPYMAX)     'and the new picture width is calculated. the file is saved as a .JPEG


    If newLeft < 0 Then

        absoluteLeft = Math.Abs(newLeft)
        newPwidth = absoluteLeft + newRight
    Else
        newPwidth = newRight - newLeft
    End If


    newimage = AxMap1.SnapShot3(newPXMIN, newPXMAX, newPYMAX, newPYMIN, newPwidth)
    newsuccess = newimage.Save(Filename1, False, MapWinGIS.ImageType.JPEG_FILE)

    If Not newsuccess Then
        MsgBox("There were errors saving the image")
        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan
        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault
    Else

        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan
        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault
        Form2.Close()
    End If