I have a function that take a bitmap, two colors and return a BitmapDrawable :
// Theme function
static public BitmapDrawable pFilter(Bitmap bitmap, int backgroundColor, int foregroundColor)
{
Bitmap bitmapCopy = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), null, true);
int[] pixels = new int[bitmapCopy.getByteCount()];
bitmapCopy.getPixels(pixels, 0, bitmapCopy.getWidth(), 0, 0, bitmapCopy.getWidth(), bitmapCopy.getHeight());
// Call native function
bitmapCopy.setPixels(pixels, 0, bitmapCopy.getWidth(), 0, 0, bitmapCopy.getWidth(), bitmapCopy.getHeight());
BitmapDrawable finalDrawable = new BitmapDrawable(Application.getAppContext().getResources(), bitmapCopy);
return finalDrawable;
}
// Custom Imageview
public class CustomImageView extends ImageView
{
private BitmapDrawable sourceImage;
private CustomTheme theme;
// [...]
private void refreshImageView()
{
super.setImageDrawable(theme.pFilter(sourceImage.getBitmap(), theme.backgroundColor, theme.foregroundColor));
}
My problem is that after about 80 calls to this function (with 10px*10px bitmaps), I get a OutOfMemory exception on this line :
int[] pixels = new int[bitmapCopy.getByteCount()];
Thanks.