我尝试对图像应用对比度,但我找不到一个好的公式来做到这一点。我尝试了许多不同的网站公式,但没有一个有效。有人有什么建议吗?
这是我最近的尝试:
int r = Colors.red(pixel);
int g = Colors.green(pixel);
int b = Colors.blue(pixel);
float red = r / 255.0f;
float green = g / 255.0f;
float blue = b / 255.0f;
red = (((red - 0.5f) * amount) + 0.5f) * 255.0f;
green = (((green - 0.5f) * amount) + 0.5f) * 255.0f;
blue = (((blue - 0.5f) * amount) + 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;
那不起作用。有人有任何其他建议吗?
答案 0 :(得分:1)
我明白了!以下是寻找相同效果的完整代码。
float value = (255.0f + amount) / 255.0f;
value *= value;
for(int i = 0; i < ImageSync.previewPixels.length; i++){
int pixel = ImageSync.previewPixels[i];
int r = Colors.red(pixel);
int g = Colors.green(pixel);
int b = Colors.blue(pixel);
float red = r / 255.0f;
float green = g / 255.0f;
float blue = b / 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;
ImageSync.previewPixels[i] = Colors.rgba(iR, iG, iB);
}