Android examples for Graphics:Bitmap Scale
Convert Bitmap to gray scale
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; public class Main { public static Bitmap toGrayscale(Bitmap original) { return bitmapFilter(original, (ColorMatrixColorFilter) null); }//from w w w. j a v a2 s . co m public static Bitmap bitmapFilter(Bitmap original, float[] matrix) { return bitmapFilter(original, new ColorMatrixColorFilter(matrix)); } public static Bitmap bitmapFilter(Bitmap original, ColorMatrixColorFilter cmcf) { Bitmap bmpGrayscale = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); if (cmcf == null) { ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); cmcf = new ColorMatrixColorFilter(cm); } paint.setColorFilter(cmcf); c.drawBitmap(original, 0, 0, paint); return bmpGrayscale; } }