此ImageBrightener方法应该通过增加颜色值来增亮图像。每个值应该增加它与255之间距离的一半。因此,155将转到205而205将转到230,依此类推。任何人都可以帮助找出ImageBrightener的问题!感谢
import squint.SImage;
public class ImageBrightener implements ImageTransformer {
@Override
public SImage transform(SImage picture) {
return BrightenImage(picture);
}
private static SImage BrightenImage(SImage si) {
int[][] newReds = BrightenImageSingleChannel(si.getRedPixelArray());
int[][] newGreens = BrightenImageSingleChannel(si.getGreenPixelArray());
int[][] newBlues = BrightenImageSingleChannel(si.getBluePixelArray());
return new SImage(newReds, newGreens, newBlues);
}
// Here is the code to brighten the image and is not functioning properly
private static int[][] BrightenImageSingleChannel(int[][] pixelArray) {
private static int[][] BrightenImageSingleChannel(int[][] pixelArray) {
int columns = pixelArray.length;
int rows = pixelArray[0].length;
int[][] answer = new int[columns][rows];
for (int x = 0; x < columns; x++) {
for (int y = 0; y < rows; y++) {
answer[x][y] = 255 - pixelArray[x][y] ;
answer[x][y] = answer[x][y] + pixelArray[x][y] ;
}
}
return answer;
}
}
// Here is the properly functioning code for darkening my image.
private static int[][] DarkenImageSingleChannel(int[][] pixelArray) {
int columns = pixelArray.length;
int rows = pixelArray[0].length;
int[][] answer = new int[columns][rows];
for (int x = 0; x < columns; x++) {
for (int y = 0; y < rows; y++) {
answer[x][y] = (255 * 2) / 3 - pixelArray[x][y];
}
}
return answer;
}
}
答案 0 :(得分:0)
问题出在这里
answer[x][y] = 255 - pixelArray[x][y] ;
answer[x][y] = answer[x][y] + pixelArray[x][y] ;
answer[x][y]
将始终为255。
试试这个
answer[x][y] = (pixelArray[x][y] + 255) / 2;