# Developers Planet

Peanutcalota February 2016

### How can I make this ImageBrightener method function properly?

This ImageBrightener method is supposed to brighten the image by increasing the color values. Each value should increase half the distance between it and 255. Thus, 155 would go to 205 while 205 would go to 230 and so on. Can anyone help figure out the issue with ImageBrightener! Thanks

``````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;
for (int x = 0; x < columns; x++) {
for (int y = 0; y < rows; y++) {
answer[x][y] = 255 - pixelArray[x][y] ;
}
}
}
}

// 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;
``` ```
``` ```
``` Answers Guy February 2016 The problem is here answer[x][y] = 255 - pixelArray[x][y] ; answer[x][y] = answer[x][y] + pixelArray[x][y] ; answer[x][y] will always be 255. Try this answer[x][y] = (pixelArray[x][y] + 255) / 2; ```
``` Post Status Asked in February 2016Viewed 2,104 timesVoted 5Answered 1 times Search Leave an answer ```
``` ```
``` ```
``` Quote of the day: live life .btn-primary{ background-color: #f44336 !important; border-color: #f44336 !important; } Devs Planet ® 2014-2016 www.devsplanet.com Devs Planet © all rights reserved Quick Actions Search // Used to toggle the menu on small screens when clicking on the menu button function myFunction() { var x = document.getElementById("navDemo"); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } } ```