透明位图ColorMatrix

时间:2016-04-21 17:02:40

标签: android bitmap

所以我的问题是我想让我的照片透明,但是当我保存它时我会变暗。因此,在我之前我必须将位图ARGB更改为0,0,0,0时,否则它将是黑色,我将遇到相同的问题。所以我这样做了:

Bitmap.Config config = bmp.getConfig();
    if (config == null) {
        config = Bitmap.Config.ARGB_8888;
    }

    operation = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), config);
    operation.eraseColor(Color.argb(0, 0, 0, 0));

但问题是没有任何改变。有什么想法吗?

我的完整代码:

public void brightne(View view) {
    float contrast = 1;
    float brightness = 0;


    Bitmap.Config config = bmp.getConfig();
    if (config == null) {
        config = Bitmap.Config.ARGB_8888;
    }

    operation = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), config);
    operation.eraseColor(Color.argb(0, 0, 0, 0));

    ColorMatrix cm = new ColorMatrix(new float[]
            {
                    contrast, 0, 0, 0, brightness,
                    0, contrast, 0, 0, brightness,
                    (float) 0.5, 0, contrast, 0, brightness,
                    0, 0, 0, 1, 0
            });
    Canvas canvas = new Canvas(operation);

    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    canvas.drawBitmap(bmp, contrast, brightness, paint);

    im.setImageBitmap(operation);


}

操作。是我的最终位图。 // bmp是我从相机中获得的照片。

0 个答案:

没有答案