gpt4 book ai didi

android - 以编程方式增强 ImageView 亮度

转载 作者:行者123 更新时间:2023-12-01 08:57:07 27 4
gpt4 key购买 nike

我有一个 android 应用程序,我正在使用下面的代码增加图像的亮度。但这非常慢,所以有没有人知道在 android 中增强 ImageView 的图像亮度的快速方法。请记住,这是提高 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;

}

这是 ImageView
imageview.setImageBitmap(doBrightness(image, 40));

最佳答案

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

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

笔记 :
对比度:0 到 10
亮度:-255 到 255

关于android - 以编程方式增强 ImageView 亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26507139/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com