我遇到调整位图对比度的函数问题。
此功能由2个搜索栏设置,当我更改搜索栏上的第一个值时,一切都很好,但是当第二个搜索栏上的值从0到99时,没有任何变化。仅当值为100时,位图才会发生变化并获得对比效果。
public Bitmap applyRGBFilters2(Bitmap src, int valueContrast, int valueBrightness){
int width = src.getWidth();
int height = src.getHeight();
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
int A, R, G, B;
int pixel;
double contrast = Math.pow((100 + valueContrast) / 100, 2);
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(R < 0) { R = 0; }
else if(R > 255) { R = 255; }
G = Color.green(pixel);
G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(G < 0) { G = 0; }
else if(G > 255) { G = 255; }
B = Color.blue(pixel);
B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(B < 0) { B = 0; }
else if(B > 255) { B = 255; }
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
Bitmap bmOut2 = Bitmap.createBitmap(bmOut);
Bitmap bmOut3 = Bitmap.createBitmap(width, height, bmOut2.getConfig());
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = bmOut3.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
R += valueBrightness;
if(R > 255) { R = 255; }
else if(R < 0) { R = 0; }
G += valueBrightness;
if(G > 255) { G = 255; }
else if(G < 0) { G = 0; }
B += valueBrightness;
if(B > 255) { B = 255; }
else if(B < 0) { B = 0; }
bmOut3.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut3;
}
你认为这里有什么不对吗?