I work on simple app with animation. I use standard View. In onDraw metod my app paints background (stored as a Bitmap) and a couple of sprites. In the main loop I need to modify the background bitmap (code attached). I use for that setPixel() metod. From time to time when I try to change bitmap I receive in the LogCat such message: "Cannot generate texture from the bitmap". After that bacground still appears on the screen but I can't use neither getPixel() nor setPixel() methods. I found some hint that it is because bitmap was recycled but I added some controls in my app and after this "crash" bitmap.isRecycled() is still false and bitmap.isMutable() is still true. So, I have no idea what's the problem.
public void drawOnBmp (float xF, float yF, float r) {
float[][] kolo;
float xP, yP;
float xStart, yStart;
xStart = xF - r / 2;
yStart = yF - r / 2;
kolo = new float[(int)r + 1][(int)r + 1];
for (int i = 0; i < 360; i++) {
xP = r / 2 + (float)(r / 2 * Math.cos(2 * Math.PI * (double)i / 360));
yP = r / 2 + (float)(r / 2 * Math.sin(2 * Math.PI * (double)i / 360));
kolo[(int)xP][(int)yP] = 1;
}
boolean start;
for (int i = 0; i < (int)r + 1; i++) {
start = false;
for (int j = 0; j < (int)r + 1; j++) {
if (kolo[i][j] == 1)
if (start == false) start = true;
else if (j >= r / 2) break;
if (start == true) kolo[i][j] = 1;
}
}
// obraz is a bitmap with background
for (int i = 0; i < (int)r; i++) {
for (int j = 0; j < (int)r; j++) {
if(kolo[i][j] == 1 && (int)xStart + i >= 0 && (int)yStart + j >= 0 &&
(int)xStart + i < obraz.getWidth() && (int)yStart + j < obraz.getHeight())
obraz.setPixel((int)xStart + i, (int)yStart + j, 0);
}
}
}
}