mapview.getMapDrawingCache() returns null

3106
20
12-30-2011 12:17 PM
SwatiGadey
New Contributor
I am trying to create a bitmap image of the Map (MapView object) as follows:

Bitmap drawingCache = mapview.getDrawingCache(true);
Btimap bitmap = mapview.getDrawingMapCache(0, 0, mapview.getWidth(), mapview.getHeight());
Bitmap drawingCache = mapview.getDrawingCache(false);


This returns a null in my 'bitmap' object. What is the correct way of using mapview.getMapDrawingCache method for getting map image?
0 Kudos
20 Replies
ArchanaAgarwal
New Contributor III
Please try getDrawingMapCache()
0 Kudos
SwatiGadey
New Contributor
Sorry for the confusion. I meant using mapview.getDrawingMapCache() (Sorry about the typo). This returns null.
Earlier, I had been using mapview.getDrawingCache() to get the map image, which is not working either. Instead of the map's image, now I get a blank image with black background.
0 Kudos
SwatiGadey
New Contributor
@Archana - Meanwhile, I had implemented getting the map image using the following snippet:

          // Code in "OnLongPressListener"
                       ------------
                       ------------
                        map.setDrawingCacheEnabled(true);

   Bitmap drawingCache = map.getDrawingCache(true);
   Log.d(TAG,"Drawing cache = " + drawingCache.getWidth()); // 480

   Bitmap bitmap = Bitmap.createBitmap(drawingCache, 0, 0, drawingCache.getWidth(), drawingCache.getHeight());
   Log.d(TAG,"Bitmap cache = " + bitmap.getWidth()); // 480
   map.setDrawingCacheEnabled(false);

                       ------------
                       ------------


                       protected void onDraw(Canvas canvas) {
   if (X > 0 && Y > 0) {

    Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, (int) X - 35, (int) Y - 35, 70, 70);
    Log.d(TAG, "cropped bitmap = " + croppedBitmap.getWidth());   // 70

    int left = (int) X - 75;
    int top = (int) Y - 150;
    int right = (int) X + 75;
    int bottom = (int) Y;
    RectF dst = new RectF(left, top, right, bottom);

    canvas.drawBitmap(croppedBitmap, null, dst, new Paint());
                                -------------
                                -------------
                       }



This worked before the SDK release (with the Beta version). However, returns me a black image now (and not a map image). Am I going wrong somewhere here?
Thanks for your help.
0 Kudos
BradFrecker
New Contributor
I'm seeing the same thing.  Is this a problem with the SDK, or are we doing something wrong?
0 Kudos
SwatiGadey
New Contributor
My understanding is that this is a bug, which ESRI is working on.

You may also want to check out the response from ESRI DEV in Thread: Magnify tool
http://forums.arcgis.com/threads/45706-Magnify-tool
0 Kudos
ArchanaAgarwal
New Contributor III
Fundamentally the first two coordinates must be screen coordinates. If you have that correct it should just work.
We will be releasing shortly, this functionality should work.

map.setOnSingleTapListener(new OnSingleTapListener() {
  
   @Override
   public void onSingleTap(float arg0, float arg1) {
                                Bitmap bitmap =  map.getDrawingMapCache(arg0,arg1,100,100);   
    ImageView img = new ImageView(ClassName.this);
    img.setImageBitmap(bitmap);
   
    map.addView(img);}});
0 Kudos
SimonKlein
Occasional Contributor
This still does not work for me in 1.1
I copied this code in the onSingleTap of the Rotation sample.
The Bitmap is always null.
Tested on Android 4.0.4. and 3.2.
0 Kudos
SimonKlein
Occasional Contributor
Did anybody find a solution for this?
0 Kudos
SimonKlein
Occasional Contributor
ok i found one. ugly but it works:
while (mailBitmap == null) {
     mailBitmap = mMapView.getDrawingMapCache(0f, 0f,
       mMapView.getWidth(), mMapView.getHeight());
    }

The first time you try it it takes up to 1400 attempts, but after that it gets quicker.
0 Kudos