【问题标题】:android colormatrix for black color用于黑色的 android colormatrix
【发布时间】:2012-02-05 22:50:51
【问题描述】:

我正在使用以下代码使我的图片变黑

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);

但颜色矩阵似乎不正确,请您帮帮我

【问题讨论】:

    标签: android colormatrix


    【解决方案1】:

    当然,对于黑色,所有颜色分量都需要 0。唯一需要担心的是阿尔法。保持原样。

                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 为零,将 1 更改为 0,要强制 alpha ff 将最后的 0 更改为 1 或 255 我不确定哪个,试试看。

    ColorMatrix 文档。

    【讨论】:

    • 你能帮我理解每一个吗:(
    猜你喜欢
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多