开发者

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

开发者 https://www.devze.com 2023-01-02 16:56 出处:网络
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 Bitm

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

精彩评论

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