- public Bitmap getBlackStyle(Bitmap src) {
- Bitmap dst = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Config.ARGB_8888);
- Canvas canvas = new Canvas(dst);
- ColorMatrix cm = new ColorMatrix();
- //设定图像为灰色,通过查资料 R 0.3 G0.59 B 0.11
- cm.set(new float[] {
- 0.3f,
- 0.59f,
- 0.11f,
- 0,
- 0,
- 0.3f,
- 0.59f,
- 0.11f,
- 0,
- 0,
- 0.3f,
- 0.59f,
- 0.11f,
- 0,
- 0,
- 0,
- 0,
- 0,
- 1,
- 0
- });
- Paint paint = new Paint();
- paint.setColorFilter(new ColorMatrixColorFilter(cm));
- canvas.drawBitmap(src, 0, 0, paint);
- // 保存图像
- canvas.save(Canvas.ALL_SAVE_FLAG);
- // 存储
- canvas.restore();
- return dst;
- }
来源: http://lib.csdn.net/snippet/android/49124