When anyDensity=false why does getDrawingCache(true) return null?
- by Robert Nekic
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?