2011-12-26 30 views

Trả lời

0

để chuyển đổi hình ảnh để phác họa bút chì bạn cần phải áp dụng 3 các bộ lọc

  1. Grayscale LỌC

  2. Invert THE COLORS

  3. GAUSSIAN BLUR

sau khi áp dụng thành công các bộ lọc này sử dụng chức năng colordodgeblend để làm bút chì như phác thảo

Grayscale lọc

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

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

MÃ ĐỂ ÁP DỤNG Invert LỌC

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

MÃ CHO gaussian blur

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

Các vấn đề liên quan