2015-08-19 54 views
1

我想加深對位圖所有黑色文本過濾的位圖和研究後,我發現這一點:JAVA安卓:變暗黑色字母/文字上的位圖

private static void setContrast(ColorMatrix cm, float contrast) { 
       float scale = contrast + 1.f; 
        float translate = (-.5f * scale + .5f) * 255.f; 
       cm.set(new float[] { 
         scale, 0, 0, 0, translate, 
         0, scale, 0, 0, translate, 
         0, 0, scale, 0, translate, 
         0, 0, 0, 1, 0 }); 
     } 

我現在的挑戰是將它在位圖上使黑色文本變暗。 請幫助我。

回答

2

我能找到使用 https://stackoverflow.com/a/17887577/5220210http://android.okhelp.cz/bitmap-set-contrast-and-brightness-android/

public static Bitmap darkenText(Bitmap bmp, float contrast) 
{ 
    ColorMatrix cm = new ColorMatrix(); 
    float scale = contrast + 1.f; 
    float translate = (-.5f * scale + .5f) * 255.f; 
    cm.set(new float[] { 
     scale, 0, 0, 0, translate, 
     0, scale, 0, 0, translate, 
     0, 0, scale, 0, translate, 
     0, 0, 0, 1, 0 }); 

    Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig()); 

    Canvas canvas = new Canvas(ret); 

    Paint paint = new Paint(); 
    paint.setColorFilter(new ColorMatrixColorFilter(cm)); 
    canvas.drawBitmap(bmp, 0, 0, paint); 

    return ret; 
} 

希望它可以幫助別人的答案,我的問題。