write a program that isolates each pixel's colour to only its brightest channel. eg: • Bright red will stay bright red • Black will stay black • Nearly-white with a bluish tint will be only bright blue For pixels where there's a tie for the 'brightest channel', it doesn't matter how you break that tie.
while ( aPic.hasNext() ) {
p = aPic.next(); // set p to the next pixel
r = p.getRed();
g = p.getGreen();
b = p.getBlue();
int maxChannelValue = Math.max(r, g, b); // figure out the value of the brightest channel
// maxChannelValue is an int that equals one (or more) of r, g, or b
if (maxChannelValue == r) { // if red is the brightest channel
p.setGreen(0);
p.setBlue(0); // turn off the non red values
} else if (maxChannelValue == g) { // same but for green
p.setRed(0);
p.setBlue(0);
} else { // same but for blue
p.setRed(0);
p.setGreen(0);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.