Android Bitmap Color Change doBrightness(Bitmap src, int value)

Here you can find the source of doBrightness(Bitmap src, int value)

Description

Adjust brightness of bitmap.

Parameter

Parameter Description
src the src
value the value

Return

the bitmap

Declaration

public static Bitmap doBrightness(Bitmap src, int value) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    /**/*from w  ww  .  j a  v a 2  s  .  c  o  m*/
     * Adjust brightness of bitmap.
     * 
     * @param src
     *            the src
     * @param value
     *            the value
     * @return the bitmap
     * @author siddhesh
     */
    public static Bitmap doBrightness(Bitmap src, int value) {
        // image size
        int width = src.getWidth();
        int height = src.getHeight();
        // create output bitmap
        Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
        // color information
        int A, R, G, B;
        int pixel;

        // scan through all pixels
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                // get pixel color
                pixel = src.getPixel(x, y);
                A = Color.alpha(pixel);
                R = Color.red(pixel);
                G = Color.green(pixel);
                B = Color.blue(pixel);

                // increase/decrease each channel
                R += value;
                if (R > 255) {
                    R = 255;
                } else if (R < 0) {
                    R = 0;
                }

                G += value;
                if (G > 255) {
                    G = 255;
                } else if (G < 0) {
                    G = 0;
                }

                B += value;
                if (B > 255) {
                    B = 255;
                } else if (B < 0) {
                    B = 0;
                }

                // apply new pixel color to output bitmap
                bmOut.setPixel(x, y, Color.argb(A, R, G, B));
            }
        }

        // return final image
        return bmOut;
    }
}

Related

  1. changeHue(Bitmap bmp, int hue, int width, int height)
  2. createAnaglyphBitmap(Bitmap bitmap)
  3. createSaturatedBitmap(final Bitmap bitmap)
  4. dilate(Bitmap bitmap, int[][] se)
  5. dilate(Bitmap source, Bitmap target, int[][] se)
  6. erosion(Bitmap bitmap, int[][] se)
  7. getGrayscaleHistogram(Bitmap bm)
  8. increaseGreen(Bitmap src, int value)
  9. initAlphaChannel( BitmapFactory.Options bitmapOptions)