Fast image binarization on Android
You can get rid of the nested loop, replacing this

for ( int x = 0; x &lt; bm.getWidth(); x++ )
 {
     for ( int y = 0; y &lt; bm.getHeight(); y++ )
     {
         c = pixels[x+y*w];
         lLightness = ((c&amp;0x00FF0000 )&gt;&gt;16) + ((c &amp; 0x0000FF00 )&gt;&gt;8) + (c&amp;0x000000FF);
         pixels[x+y*w] = lLightness;
         gLightness += lLightness;
     }
 }


With this:

int size = bm.getWidth()*bm.getHeight();
for (int i = 0; i &lt; size; i++) {
  c = pixels[i];
 // etc.
}


It will at least save one x+y*w operation per pixel.

It may be advantageous to calculate size into a separate variable as above, instead of doing it inside the loop, as in for (int i = 0; i &lt; bm.getWidth()*bm.getHeight(); i++). The condition is checked at each round so you would end up calling the getters at each round, and who knows what's in them? The JIT compiler may be able to optimize this kind of stuff away - and probably will, if the getters are simple "return class member" statements - but at least it's not guaranteed.

More substantial improvements can be got by sacrificing perfection. Maybe you needn't take each pixel into account for calculating the threshold? Perhaps count only every 10th on each direction? Then you would probably use the nested loop again. Like this:

int width = bm.getWidth();
int height = bm.getHeight();

for ( int x = 0; x &lt; width; x+=10; )
{
  for ( int y = 0; y &lt; height; y+=10; )
  {
   // etc.
  }
}

gLightness /= (width / 10) * (height / 10);