JAVA Android: Darkening black letters/texts on a bitmap -
i want darken black text on bitmap filter the bitmap , after research found this:
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 }); }
my present challenge applying on bitmap darken black texts. kindly assist me.
i able find answer question using https://stackoverflow.com/a/17887577/5220210 , http://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; }
hope helps someone.
Comments
Post a Comment