如何使用Paint操作位图

时间:2018-12-20 08:26:22

标签: android image-processing colors drawable

我需要使用此选项创建图像。图像必须是白色,例如灰度,但是使用红色混合,在这种情况下,我使用的是Bitmap,Paint和Canvas,但是当应用程序启动时,代码仅适用灰度。你能帮我吗?

private Drawable getStylishImage (Bitmap bitmap){
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(matrix);
    ColorFilter filter = new LightingColorFilter(Color.RED, 0);
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY));
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);
    return new BitmapDrawable(getResources(), mutableBitmap);
}

0 个答案:

没有答案