9

I am developing a Image editing app for Android. For this I need to convert my image to a pencil sketch.

Can you please help me in this.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1105428
  • 91
  • 1
  • 2

2 Answers2

4

You require some image processing library to do that.
You can try ImageJ or Marvin.

For more information, you can refer this SO post: What is the best java image processing library/approach?

Community
  • 1
  • 1
Karthik
  • 3,509
  • 1
  • 20
  • 26
0

TO Convert The Image to pencil sketch you need to apply 3 filters

  1. GRAYSCALE FILTER

  2. INVERT THE COLORS

  3. GAUSSIAN BLUR

after successfully applying these filters use colordodgeblend function to make pencil like sketch

Grayscale filter

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

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

CODE TO APPLY 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);

CODE FOR 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

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
sKv
  • 66
  • 6