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

时间:2011-12-26 05:53:00

标签: android image

我正在为Android开发图像编辑应用。为此,我需要将我的图像转换为铅笔草图。

你可以帮助我。

2 个答案:

答案 0 :(得分:4)

你需要一些图像处理库才能做到这一点 您可以尝试ImageJMarvin

有关详细信息,请参阅此SO帖子:What is the best java image processing library/approach?

答案 1 :(得分:0)

要将图像转换为铅笔草图,您需要应用3个过滤器

  1. GRAYSCALE FILTER

  2. 反转颜色

  3. GAUSSIAN BLUR

  4. 成功应用这些滤镜后,使用colordodgeblend函数制作铅笔,如草图

    灰度滤镜

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

    GAUSSIAN BLUR的代码

    with t0_t1 as (
      select 
        t.id,
        t.nm, 
        count(t1.id) as A
      from table0 t
      left join table1 t1 on t.id = t1.id
      group by t.id, t.nm
    )
    select t.nm, t.A, count(t2.id) as B
    from t0_t1 t
    left join table2 t2 on t.id = t2.id
    group by t.nm, t.A
    

    for more reference