开发者

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

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开发者_Python百科 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?


Did you use getDrawingCache in onCreate?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜