我正在开发一款Android图像编辑应用程序。为此,我需要将我的图像转换为铅笔素描。
您能帮助我吗?
将图像转换为铅笔素描需要应用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);
}