2

I have an Activity which contains a MapFragment V2 on half of the screen, and on the other half there are some more views such as TextViews with details.

This how the screen looks like: enter image description here

Now, I want to take a snapshot of the whole activity include the MapFragment but when I try to do that, I do get an image but the map part is blank (totally black)!

This is the code I am using for taking the screenshot and it works great!

I do know about the option to take a snapshot of the MapFragment but it takes only the map area without the rest of the screen. Something like this:

GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                // TODO Auto-generated method stub
                FileOutputStream out = null;
                boolean status = true;
                try {
                    out = new FileOutputStream(sharedImage);
                    snapshot = Bitmap.createScaledBitmap(snapshot, findViewById(R.id.trip_map).getWidth(),
                            findViewById(R.id.trip_map).getHeight(), true);
                    status = snapshot.compress(Bitmap.CompressFormat.JPEG, 100, out);
                    Toast.makeText(TripDetailsActivity.this, "save status: " + status, Toast.LENGTH_SHORT).show();
                    snapshot.recycle();
                    snapshot = null;
                    System.gc();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        out.flush();
                        out.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                openShareImageDialog(sharedImage);
            }
        };
        mMap.snapshot(callback);

    }
    return true;
}

Does anyone have an idea how can I take the whole screen snapshot when there is a MapFragment there?

Moti Bartov
  • 3,454
  • 33
  • 42
  • AFAIK Google uses OpenGL to render the map and there's no way to grab screenshot of OpenGL views (except the GoogleMap take snapshot). – harism Jul 25 '15 at 18:38

2 Answers2

0

Try this in my case its working for me, i know both are same, but try with LinearLayout as parent, Keep all your elements in one parent layout and take screen shot when ever you want :

 public void getDrawingBitmap() throws Exception{

 LinearLayout tabLayout = (LinearLayout)findViewById(R.id.screen_shot_layout);

    if (tabLayout != null) {

        Bitmap image = Bitmap.createBitmap(tabLayout.getWidth(),
                tabLayout.getHeight(), Config.ARGB_8888);
        Canvas b = new Canvas(image);
        tabLayout.draw(b);
        if (image!=null) {
            // here is your sceenshot
        }else{
            Toast.makeText(DashBord.this, "Unabel to take screen shot", Toast.LENGTH_LONG).show();
        }
    }



}
Guruprasad
  • 931
  • 11
  • 16
0

You can use google map callback function like this:

GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                // create bitmap screen capture
                Bitmap bitmap = snapshot;

                OutputStream fout = null;
                File imageFile = new File(filePath);

                try {
                    fout = new FileOutputStream(imageFile);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
                    fout.flush();
                    fout.close();

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };

Now call using your Google Map fragment:

map.snapshot(callback);
Quan Nguyen
  • 5,074
  • 3
  • 24
  • 26