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.