Hello,
I am trying to take a snapshot of an map. I use a selection box to define the boundaries. Then zoom in a bit. I track the new pixel locations of the boundaries and attempt to use snapshot3 to then create the image. but when I do, I get the below error…It should be noted I also get this error when I do not zoom in or when I try to set the boundaries manually, as opposed to using the selection box.
Error msg: System.NullReferenceException: ‘Object reference not set to an instance of an object.’
Public Sub SomeTrickyMath()
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
Filename1 = "C:\sitepad\" & mMapFile & "-" & ScreenGrabCount & "-" & DateString & ".tiff"
AxMap1.ProjToPixel(pxMin, pyMin, newLeft, newDown)
AxMap1.ProjToPixel(pxMax, pyMax, newRight, newUp)
AxMap1.PixelToProj(newLeft, newDown, newPXMIN, newPYMIN)
AxMap1.PixelToProj(newRight, newUp, newPXMAX, newPYMAX)
If newLeft < 0 Then
System.Diagnostics.Debug.WriteLine("left pxel is off screen high!")
absoluteLeft = Math.Abs(newLeft)
newPwidth = absoluteLeft + newRight
Else
newPwidth = newRight - newLeft
End If
newimage = AxMap1.SnapShot3(newLeft, newRight, newUp, newDown, newPwidth)
newsuccess = newimage.Save(Filename1, False, MapWinGIS.ImageType.TIFF_FILE)
System.Diagnostics.Debug.WriteLine("image width in pixels is: " & newPwidth)
System.Diagnostics.Debug.WriteLine("bottom left corner:" & newLeft & "::" & newDown)
System.Diagnostics.Debug.WriteLine("TopRight Corner:" & newRight & "::" & newUp)
End Sub
Private Sub AxMap1_SelectBoxFinal(sender As Object, e As _DMapEvents_SelectBoxFinalEvent) Handles AxMap1.SelectBoxFinal
'Dim pxMin, pxMax, pyMin, pyMax As Double
leftPix = e.left
rightPix = e.right
upPix = e.top
downPix = e.bottom
AxMap1.PixelToProj(e.left, e.bottom, pxMin, pyMin)
AxMap1.PixelToProj(e.right, e.top, pxMax, pyMax)
'myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0)
'pWidth = e.right - e.left
Form2.Show()
'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(ProjectChartLayer)
System.Diagnostics.Debug.WriteLine("Left and right pixel locations : Left - " & e.left & "right- " & e.right)
System.Diagnostics.Debug.WriteLine("capture width in pixels: " & pWidth)
System.Diagnostics.Debug.WriteLine("Bottom left corner: " & pxMin & "-" & pyMin)
System.Diagnostics.Debug.WriteLine("Top Right corner: " & pxMax & "-" & pyMax)
End Sub
Im handling the selection box within the SelectboxFinal event handler. I do not think my problem is with defining my boundaries. It works fine with setting the extents for the snapshot method. But I think I am doing something wrong with the Snapshot3 method and that is creating this error. I am creating an image object, Is there a better way then “Dim image as new mapwingis.image” ? Is there an error with the data I am sending to that Snapshot3 method?
When I try to take the snapshot without zooming I get the error. If I zoom in I also get the error. When I zoom in I notice that the left and top pixel locations go negative (all of the boundaries are off screen at this point). can the method take negative numbers?
If anyone can point me to more literature or examples of the snapshot3 method being used that would be very helpful as my google-kung-fu has turned up little. I appreciate any and all help!!
Regards,
Eric