我正在使用下面的代码来使我的图片变黑
BitmapDrawable bdarw = new BitmapDrawable(imagePath);
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
2, 1f, 0, 0, 0,
0, 2, 0f, 0, 0,
0, 0, 2, 0f, 0,
0, 0, 0, 1f, 0 });
bdarw.setColorFilter(new ColorMatrixColorFilter(cm));
Bitmap bitmap= bdarw.getBitmap();
ImageView imageView = (ImageView) findViewById(R.id.imgV);
imageView.setImageBitmap(bitmap);但是看起来颜色矩阵不正确,你能帮我吗?
发布于 2012-02-04 15:49:09
当然,对于黑色,所有的颜色分量都需要0。唯一需要担心的是alpha。让它保持你想要的样子。
cm.set(new float[] {
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 1f, 0 }); 要强制alpha为0,将1改为0,强制alpha为ff,将最后的0改为1或255我不确定是哪一个,试一试看看。
ColorMatrix文档。
https://stackoverflow.com/questions/9138797
复制相似问题