0

I want to take a snapshot of my map:

SnapshotReadyCallback callback = new SnapshotReadyCallback() {
    Bitmap bitmap;
    @Override
    public void onSnapshotReady(Bitmap snapshot) {
        // TODO Auto-generated method stub
        bitmap = snapshot;
    }
};

map.snapshot(callback);

But it gives me this error:

width and height must be > 0

André Dion
  • 21,269
  • 7
  • 56
  • 60
David
  • 2,331
  • 4
  • 29
  • 42

1 Answers1

1

You are making a mistake of calling snapshot too early. Before all Views are layed out, they have a size of 0 by 0.

It's best to use this function on users action, e.g. in some Button's onClick.

If you need it after the map is shown, you can try with ViewTreeObserver. Check this answer: https://stackoverflow.com/a/7735122/2183804.

Community
  • 1
  • 1
MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • ok i made it for in a button listener. if i run it it does nothing i think or i don't know where is it save the image... – David Aug 14 '13 at 12:22
  • @David Bitmap is returned to you via `Bitmap snapshot` parameter. The easiest way to check it worked, is e.g. setting background of the `Button` to this `Bitmap`. – MaciejGórski Aug 14 '13 at 12:25