I am trying to convert a image I take with drawView.getDrawingCache()
When I run the code I don't get any errors, but it hangs with
11-20 15:43:14.208 28960-28960/edu.umass.ecs.chalkmaster3000 D/dalvikvm﹕ GC_FOR_ALLOC freed 285K, 8% free 19838K/21379K, paused 24ms, total 35ms
11-20 15:44:17.666 5502-5519/? W/ActivityManager﹕ Activity stop timeout for ActivityRecord{42e17c78 edu.umass.ecs.chalkmaster3000/.MainActivity}
Below is the code I am running
public Bitmap grayToBlackWhite(Bitmap b)
{
Bitmap chanagebleBitMap = b.copy(Bitmap.Config.ARGB_8888, true);
int[] pixels = new int[1];
if(b != null){
int picw = chanagebleBitMap.getWidth();
int pich = chanagebleBitMap.getHeight();
pixels = new int[picw*pich];
chanagebleBitMap.getPixels(pixels, 0, picw, 0, 0, picw, pich);
int R, G, B,Y;
for (int y = 0; y < pich; y++){
for (int x = 0; x < picw; x++)
{
int index = y * picw + x;
R = (pixels[index] >> 16) & 0xff; //bitwise shifting
G = (pixels[index] >> 8) & 0xff;
B = pixels[index] & 0xff;
if(((R+G+B)/3)>128)
R=G=B=150;
else
R=G=B=0;
//R,G.B - Red, Green, Blue
//to restore the values after RGB modification, use
//next statement
pixels[index] = 0xff000000 | (R << 16) | (G << 8) | B;
chanagebleBitMap.setPixels(pixels, 0, chanagebleBitMap.getWidth(), 0, 0, chanagebleBitMap.getWidth(), chanagebleBitMap.getHeight());
}
}
}
return chanagebleBitMap;
}
The line that causes the issue is the setPixels call.
I have no experience with this type of problem, any hints or help would be much appreciated. Thanks!
After reading your response I went and took a look with the android debug monitor. Here is a picture of what I am seeing.
Nothing seems to be too out of check, does it to you?
I did more more debugging. The width and height of my original picture I am trying to convert is 700 by 886 pixels. When I create the int array it is 620200 in size! Multiply this by 4 (since each int is 4 bytes) and the size is 2 gigs!?!?
If this is correct, I understand why I am getting the memory error, but how would I go about doing what I need if this is the case?
As always, Thanks!