Android Question Screenshot the content of Google Maps?

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, I followed the Erel´s tutorial:

Google Maps Android v2 tutorial

And the map shows on the app, then I try To use this code to capture a picture of the map:

B4X:
Sub GetMap
  Dim Obj1, Obj2 As Reflector
  Dim bmp As Bitmap
  Dim c As Canvas
 
  Obj1.Target = Obj1.GetActivityBA
  Obj1.Target = MapPanel
 
  bmp.InitializeMutable(MapPanel.Width, MapPanel.Height)
  c.Initialize2(bmp)
  Dim args(1) As Object
  Dim types(1) As String
  Obj2.Target = c
  Obj2.Target = Obj2.GetField("canvas")
  args(0) = Obj2.Target
  types(0) = "android.graphics.Canvas"
  Obj1.RunMethod4("draw", args, types)
  Dim Out As OutputStream
  Out = File.OpenOutput(File.DirDefaultExternal, "map.png", False)
  bmp.WriteToStream(Out, 100, "PNG")
  Out.Close
End Sub

Taken from: http://www.b4x.com/android/forum/threads/how-to-make-screenshots.10199/#post-56790



The problem is that the image it only has the Google's logo and the zoom buttons, but not the map.

Is there a better way to save a picture of the Google Maps?

Thanks
 

ivan.tellez

Active Member
Licensed User
Longtime User
Wow, thanks, its really easy with GoogleMapsExtras.

For others looking for the code:

B4X:
Sub Globals
Dim MapEx As GoogleMapsExtras
End Sub


Sub BtnSaveMap_Click
MapEx.Snapshot(gmap, "gmap")
End Sub


Sub gmap_SnapshotReady (Bitmap1 As Bitmap)
   
    If File.Exists(File.DirDefaultExternal, "map.png") Then File.Delete(File.DirDefaultExternal, "map.png")
    Dim out As OutputStream
    out = File.OpenOutput(File.DirDefaultExternal, "map.png", False)
    Bitmap1.WriteToStream(out, 100, "PNG")
    out.Close

End Sub


Only a question. This way you get the image Asyncronously, Is there a way to get the image Syncronously?

Thanks
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I have Google Maps on a panel that has relevant info on both top and bottom of the Google Map view. It is sort of like a card with info for tourists. I would like to save this whole panel (containing both info as well as Google Maps) into a bitmap. I used the normal Canvas method to convert panel to bmp but the portion with Google Maps is blank. I guess I can use the Extras library to take a snapshot of Google Map but I would like to place this snapshot on to the previous screenshot of the panel so that it looks like a complete card with info on top and bottom of the Map.

Any idea how I can do this? Essentially I will have to copy the bitmap from Extras snapshot and layer it on top of the panel output bitmap.

EDIT:

You can do all this with Canvas object. Here is how.
  1. Save snapshot of the map using Extras library
  2. Take the snapshot of Panel using Canvas object
  3. Define a Rect with borders corresponding to the MapView
  4. Convert snapshot from step 1 to BitmapDrawable
  5. Using Canvas from step 2, perform Canvas.DrawDrawable with BitmapDrawable from step 5 to the Rect defined in step 3
  6. Save the Bitmap from Canvas with Canvas.Bitmap.WritetoStream
  7. Done
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…