2011-12-26 26 views

回答

0

將圖像轉換到鉛筆素描您需要申請3個濾波器

  1. GRAYSCALE FILTER

  2. INVERT THE COLORS

  3. 高斯BLUR

後成功應用這些過濾器使用colordodgeblend功能,使鉛筆草圖的

灰度過濾

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

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

代碼以進行INVERT 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); 
} 

for more reference

相關問題