How can I make / combine a screenshot from a Google v2 map and xml layout as programmatically?

I am taking a screenshot of Google Map v2 using the code for this answer , which gives me the output:

enter image description here

What is better to take a map snapshot

With the following code, I can take a screenshot with a layout with a black screen of the map, this is normal, as with the following code The map will be black in ScreenShot

String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "myTestScr" + System.currentTimeMillis() + ".jpeg"; Bitmap bitmap; View v1 = (View) findViewById(R.id.rootviewtest); v1.setDrawingCacheEnabled(true); bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); OutputStream fout = null; File imageFile = new File(mPath); try { fout = new FileOutputStream(imageFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); fout.flush(); fout.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } 

output of the above code:

enter image description here

I really need:

enter image description here

So, now My question is: how to get the output, for example, in 3rd Screen programmatically ?

Help me take one screenshot by combining screens (1 and 2) programmatically ?

or any other option to combine both images programmatically after taking screenshots (1 and 2)?

+8
android google-maps-android-api-2 screenshot
source share
2 answers

Call the following method to take a screenshot of the map:

 public void captureMapScreen() { SnapshotReadyCallback callback = new SnapshotReadyCallback() { @Override public void onSnapshotReady(Bitmap snapshot) { try { mView.setDrawingCacheEnabled(true); Bitmap backBitmap = mView.getDrawingCache(); Bitmap bmOverlay = Bitmap.createBitmap( backBitmap.getWidth(), backBitmap.getHeight(), backBitmap.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(snapshot, new Matrix(), null); canvas.drawBitmap(backBitmap, 0, 0, null); FileOutputStream out = new FileOutputStream( Environment.getExternalStorageDirectory() + "/MapScreenShot" + System.currentTimeMillis() + ".png"); bmOverlay.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { e.printStackTrace(); } } }; mMap.snapshot(callback); } 

mview is the root view of your layout, and mMap is your map fragment.

Make sure you have the latest Google Play Services API.

 mView.setDrawingCacheEnabled(true); Bitmap backBitmap = mView.getDrawingCache(); Bitmap bmOverlay = Bitmap.createBitmap( backBitmap.getWidth(), backBitmap.getHeight(), backBitmap.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(snapshot, new Matrix(), null); canvas.drawBitmap(backBitmap, 0, 0, null); 

Skip these lines and use snapshot.compress(Bitmap.CompressFormat.PNG, 90, out); if you want only a screenshot of the map.

+17
source share

I do not know the Android API, but since you requested the "alternative" methods, I suggest using ImageMagick . There are several binaries on this site, so I hope you can download the one that suits your system. Otherwise, you can download the sources (google around, and you will find many links about creating it for Android).

Since I work on a Windows computer, I can only tell you how you can call it from the Windows command line, but the syntax is similar for other platforms. This application also offers a wide selection of APIs for different languages โ€‹โ€‹(Java, C or C ++ may be of interest to you in particular), so you can use the ImageMagick built into your application, instead of calling it from the command strings.

Now for the problem under consideration: you need to perform an โ€œoverlayโ€ operation with the symbols above your map, as well as with a transparent sheet with drawings over a real map.

So call map.png and overlay.png two files you need to merge. Please note that also the overlay file is a PNG file (more on this later). Then you can get something close to what you want with the following command line call:

 composite.exe -compose atop overlay.png map.png output.jpg 

Why should the overlay be a PNG image? This is because we need an โ€œoverlay sheetโ€ that is transparent in most areas (except when you have a balloon tip and other drawings), but JPG images do not store transparency information (they donโ€™t have an alpha channel that stores this information).

So, you have to change the part of your code that generates the overlay to generate the PNG image with the corresponding alpha channel.

Hope all of this helps.

0
source share

All Articles