Here is a sample that iterates over each pixel.
/**
* @param bitmap a mutable bitmap instance.
*/
private void darkenBitmap(Bitmap bitmap) {
int height = bitmap.getHeight();
int width = bitmap.getWidth();
int pixel;
// Iterate over each row (y-axis)
for (int y = 0; y < height; y++) {
// and each column (x-axis) on that row
for (int x = 0; x < width; x++) {
pixel = bitmap.getPixel(x, y);
// TODO: Modify your pixel here. For samples, http://stackoverflow.com/questions/4928772/android-color-darker
bitmap.setPixel(x, y, pixel);
}
}
}
The method requires mutable bitmap, so you will probably need to load your bitmap with BitmapFactory options. e.g.,
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.somebitmap, options);
You might as well create a new mutable bitmap inside that method, call setPixel(...) on that and return it. But, I will strongly suggest avoiding that kind of memory allocation if possible.