When anyDensity=false why does getDrawingCache(true) return null?

Posted by Robert Nekic on Stack Overflow See other posts from Stack Overflow or by Robert Nekic
Published on 2010-06-09T14:49:50Z Indexed on 2010/06/09 14:52 UTC
Read the original article Hit count: 453

Filed under:

First off, my application currently defines anyDensity=false in the manifest file. Elsewhere in the app, I'm trying to capture and display a View's DrawingCache but I'm not able to get a clear Bitmap without scaling artifacts.

The code below yields a Bitmap but it has scaling artifacts and is generally fuzzy.

myView.setDrawingCacheEnabled(true);
Bitmap myBitmap = Bitmap.Create(myView.getDrawingCache());
myImageView.setImageBitmap(myBitmap);

As I read it, the documentation for getDrawingCache says this is to be expected and to use getDrawingCache(true). Yet, both code examples below throw NullPointer exceptions because the Bitmap returned by getDrawingCache(true) is always null.

myView.setDrawingCacheEnabled(true);
Bitmap myBitmap = Bitmap.Create(myView.getDrawingCache(true));
myImageView.setImageBitmap(myBitmap);

OR

myView.buildDrawingCache(true);
Bitmap myBitmap = Bitmap.Create(myView.getDrawingCache(true));  
myImageView.setImageBitmap(myBitmap);
myView.destroyDrawingCache();

Does anyone know how to properly capture and render the drawingCache when anyDensity=false?

© Stack Overflow or respective owner

Related posts about android