Removing the drawing cache

In my application, I want to share images at runtime when the user clicks on it.

There are two images when the user clicks on the first image and then clicks on the second image at the same time. I am extracting a bitmap of the first image of the image and assigning a second image for this, I used the following code:

public Bitmap createBitmap(ImageView imageview) { imageview.setDrawingCacheEnabled(true); imageview.buildDrawingCache(false); if(imageview.getDrawingCache() != null) { Bitmap bitmap = Bitmap.createBitmap(imageview.getDrawingCache()); imageview.setDrawingCacheEnabled(false); return bitmap; } else { return null; } } 

The code works fine, but the cache is not cleared every time and the bitmap created using the previous cache, so how can I clear the cache in raster form?

+3
android bitmap
source share
2 answers

This is an example, for example. where I use Free the native object associated with this bitmap .

 Bitmap bitmap; public Bitmap createBitmap(ImageView imageview) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } bitmap = Bitmap.createBitmap(imageview.getDrawingCache()); // Your Code of bitmap Follows here } 

Before using Bitmap, just free the object.

+2
source share

use bitmap.recycle(); before evaluating your bitmaps to clear their cache before you recreate it.

+1
source share

All Articles