如何在Android中将位图转换为铅笔素描?

9

我正在开发一款Android图像编辑应用程序。为此,我需要将我的图像转换为铅笔素描。

您能帮助我吗?

2个回答

4

0

将图像转换为铅笔素描需要应用3个滤镜

  1. 灰度滤镜

  2. 反转颜色

  3. 高斯模糊

成功应用这些滤镜后,使用colordodgeblend函数制作铅笔素描效果

灰度滤镜

ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);

ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imgView.setColorFilter(filter);

应用反相滤镜的代码

float[] colorMatrix_Negative = {
        -1.0f, 0, 0, 0, 255, //red   
         0, -1.0f, 0, 0, 255, //green
         0, 0, -1.0f, 0, 255, //blue
         0, 0, 0, 1.0f, 0 //alpha};
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(colorMatrix_Negative);

ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);

高斯模糊代码

public static Bitmap applyGaussianBlur(Bitmap src) {

    double[][] GaussianBlurConfig = new double[][]{
            {-1, 0, -1},
            {0, 4, 0},
            {-1, 0, -1}
    };

    ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);

    convMatrix.applyConfig(GaussianBlurConfig);
    convMatrix.Factor = 1;
    convMatrix.Offset = 150;
    //return out put bitmap    return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
}

更多参考资料


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接