Here is an example that iterates over each pixel.
private void darkenBitmap(Bitmap bitmap) { int height = bitmap.getHeight(); int width = bitmap.getWidth(); int pixel;
The method requires a modified bitmap, so you probably need to load the bitmap using the BitmapFactory options. eg.
BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = true; Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.somebitmap, options);
You can also create a new mutable bitmap inside this method, call setPixel (...) on it and return it. But I highly recommend avoiding such memory allocation if possible.
source share