将bitmap修改为灰阶,减小图片大小

public static 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;
}

你可能感兴趣的:(将bitmap修改为灰阶,减小图片大小)