以编程方式增强ImageView亮度

Sye*_*Ali 0 optimization android android-imageview

我有一个Android应用程序,我使用下面的代码增加图像的亮度.但这非常慢,所以有人知道在android中增强imageview图像亮度的快速方法.请记住,这是提高图像视图亮度而不是屏幕亮度

 public static Bitmap doBrightness(Bitmap src, int value) {
    //Log.e("Brightness", "Changing brightnhjh");

    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmout = Bitmap.createBitmap(width, height, src.getConfig());
    int A, R, G, B;
    int pixel;
    for (int i = 0; i < width; i=i++) {
        for (int j = 0; j < height; j=j++) {
            pixel = src.getPixel(i, j);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            R += value;
            if (R > 255) {
                R = 255;
            } else if (R < 0) {
                R = 0;
            }
            G += value;
            if (G > 255) {
                G = 255;
            } else if (G < 0) {
                G = 0;
            }
            B += value;
            if (B > 255) {
                B = 255;
            } else if (B < 0) {
                B = 0;
            }
            bmout.setPixel(i, j, Color.argb(A, R, G, B));
        }
    }
    return bmout;

}
Run Code Online (Sandbox Code Playgroud)

这是imageview

imageview.setImageBitmap(doBrightness(image, 40));
Run Code Online (Sandbox Code Playgroud)

Jas*_*aur 6

您可以使用以下代码来增强图像:

public static Bitmap enhanceImage(Bitmap mBitmap, float contrast, float brightness) {
    ColorMatrix cm = new ColorMatrix(new float[]
        {
            contrast, 0, 0, 0, brightness,
            0, contrast, 0, 0, brightness,
            0, 0, contrast, 0, brightness,
            0, 0, 0, 1, 0
        });
    Bitmap mEnhancedBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), mBitmap
        .getConfig());
    Canvas canvas = new Canvas(mEnhancedBitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    canvas.drawBitmap(mBitmap, 0, 0, paint);
    return mEnhancedBitmap;
}
Run Code Online (Sandbox Code Playgroud)

注意:
对比度:0到10亮度:-255到255