2016-02-08 31 views
0

這個ImageBrightener方法應該通過增加顏色值來增亮圖像。每個值應該增加它與255之間的一半距離。因此,155將會到達205,而205將會到230,等等。任何人都可以幫助找出ImageBrightener的問題!由於如何使此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

你看過[問]? – Amit

回答

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; 
+0

非常感謝!沒有意識到'答案[x] [y]'總是255。 – Peanutcalota