以编程方式增强ImageView的亮度 [英] Enhancing ImageView brightness programmatically

查看:102
本文介绍了以编程方式增强ImageView的亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an android app in which I am increasing brightness of image with the code below. But this is very slow so does anyone knows a fast way to enhance image brightness of an imageview in android. Keep in mind this is improving imageview brightness not screen brightness

 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;

}

这是图片视图

imageview.setImageBitmap(doBrightness(image, 40));

推荐答案

我已解决此问题,我使图像变亮,然后在imageview中显示.我使用的代码如下:

I have got a work around for this issue i made the image brighter and then shown it in an imageview. The code i used is given below:

foto.setColorFilter(brightIt(100));//foto is my ImageView
//and below is the brightIt func
public static ColorMatrixColorFilter brightIt(int fb) {
ColorMatrix cmB = new ColorMatrix();
cmB.set(new float[] { 
    1, 0, 0, 0, fb,
    0, 1, 0, 0, fb,
    0, 0, 1, 0, fb,
    0, 0, 0, 1, 0   });

ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(cmB);
//Canvas c = new Canvas(b2);
//Paint paint = new Paint();
ColorMatrixColorFilter f = new ColorMatrixColorFilter(colorMatrix);
//paint.setColorFilter(f);   
return f;
}

这篇关于以编程方式增强ImageView的亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆