使用下面的代码来对比增加了位:值的范围从1到100
public static Bitmap AdjustContrast(Bitmap original, float Value){
Value = (100.0f + Value)/100.0f;
Value *= Value;
Bitmap newBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(),original.getConfig());
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
for (int i = argb.length - 1; i >= 0; --i) {
int alpha = argb[i] >> 24;
int red = (argb[i] >> 16) & 0xFF;
int green = (argb[i] >> 8) & 0xFF;
int blue = argb[i] & 0xFF;
float Red = red/255.0f;
float Green = green/255.0f;
float Blue = blue/255.0f;
Red = (((Red - 0.5f) * Value) + 0.5f) * 255.0f;
Green = (((Green - 0.5f) * Value) + 0.5f) * 255.0f;
Blue = (((Blue - 0.5f) * Value) + 0.5f) * 255.0f;
int iR = (int)Red;
iR = iR > 255 ? 255 : iR;
iR = iR < 0 ? 0 : iR;
int iG = (int)Green;
iG = iG > 255 ? 255 : iG;
iG = iG < 0 ? 0 : iG;
int iB = (int)Blue;
iB = iB > 255 ? 255 : iB;
iB = iB < 0 ? 0 : iB;
int composite = (alpha << 24) | (iR << 16) | (iG << 8) | iB;
argb[i] = composite;
}
newBitmap.setPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
Store.lastBitmap = newBitmap;
return newBitmap;
}
使用此亮度效果:值应介于1到100之间
public static Bitmap makeBrightnessBitmap(Bitmap original, int brightness){
Bitmap newBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(),original.getConfig());
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
for (int i = argb.length - 1; i >= 0; --i) {
int alpha = argb[i] >> 24;
int red = (argb[i] >> 16) & 0xFF;
int green = (argb[i] >> 8) & 0xFF;
int blue = argb[i] & 0xFF;
int red2 = red + brightness;
if (red2>0xFF) red2 = 0xFF;
if (red2<0) red2 = 0;
int green2 = green + brightness;
if (green2>0xFF) green2 = 0xFF;
if (green2<0) green2 = 0;
int blue2 = blue + brightness;
if (blue2>0xFF) blue2 = 0xFF;
if (blue2<0) blue2 = 0;
int composite = (alpha << 24) | (red2 << 16) | (green2 << 8) | blue2;
argb[i] = composite;
}
newBitmap.setPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
Store.lastBitmap = newBitmap;
return newBitmap;
}