Image from gallery convert to grayscale by click on button (Android)

883 Views Asked by At

I want to know how to change the colour of image from the gallery by clicking on button. i have multiple activities that need to be done. I already pass the image from the gallery to the other activity by using intent. what i need to do now is to convert that image from gallery to grayscale by click on button.. could you give some idea?

and another one, what the image processing library that can used in android? thanks.

1

There are 1 best solutions below

5
On

Already answered here : Android : Converting imageview to bitmap, to grayscale, bitmap to imageview

public Bitmap toGrayscale(Bitmap bmpOriginal){        
        int width, height;
        height = bmpOriginal.getHeight();
        width = bmpOriginal.getWidth();    

        Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        Canvas c = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bmpOriginal, 0, 0, paint);
        return bmpGrayscale;
    }