user1072605
user1072605

Reputation: 99

setDrawingCacheQuality doesn't work in Android?

I tried to get View's caching bitmap, the code is as follows:

View cachingView = getActivity().getWindow().getDecorView().getRootView();
cachingView.setDrawingCacheEnabled(true);
cachingView.setLayerType(View.LAYER_TYPE_NONE,null);
cachingView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
 Bitmap bitmap = Bitmap.createBitmap(cachingView.getDrawingCache());
LogHelper.i("bitmap size: "+bitmap.getByteCount());
LogHelper.i("bitmap size: "+ BitmapCompat.getAllocationByteCount(bitmap));

The print result is :

bitmap size: 14745600

bitmap size: 14745600

Obviously,it is too big. I changed different parameters of setDrawingCacheQuality , but the result is the same.

How can I get a smaller bitmap?

Thanks

Upvotes: 0

Views: 727

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93559

The quality here isn't the quality of the compression like when writing a JPEG. Its the quality of the alpha blending for transparencies. So it does work, it just doesn't do what you thought it did.

(As an aside- Bitmaps in memory are uncompressed, so it doesn't matter what compression quality you use to write them to disk- in memory they take up the same amount of memory based if they're the same size).

Upvotes: 2

Related Questions