Java - Adjusting Brightness using Given Code?
-
This is yet another assignment of mine that I am lost on. I looked all through my textbook and could find nothing to help me. Nowhere else on the internet seemed to be able to answer my question either. I am given this code: /** *The Brightness class adjusts the brightness of the image ncstate.jpg and outputs a new image ncstate-brightened.jpg. *@author Sarah Dashow *@version 1.0 */ import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import java.util.Scanner; import javax.imageio.ImageIO; public class Brightness { public static int adjustBy; /** *The adjustColor method is what actually changes the image. */ // The following method is what I need to edit. private static int adjustColor(int color, int aB) { return color; } /** *This is the main method - see comments for more detail */ public static void main(String[] args) throws Exception { // The following main method doesn't need any modificiations // Input what to adjust by, place in the adjustBy variable System.out.print("Adjust the brightness by (-255,255): "); int adjustBy = new Scanner(System.in).nextInt(); // Read in the image in BufferedImage image = ImageIO.read(new File("ncstate.jpg")); // Loop through each pixel - we haven't done loops yet, but you'll see // them later in the semester for (int x = 0; x < image.getWidth(); x++) { for (int y = 0; y < image.getHeight(); y++) { // Get the red, green, and blue component of each pixel Color color = new Color(image.getRGB(x, y)); // Call the adjustColor method three times, one for each color // of the pixel int red = adjustColor(color.getRed(), adjustBy); int green = adjustColor(color.getGreen(), adjustBy); int blue = adjustColor(color.getBlue(), adjustBy); // Set the pixel back in the image image.setRGB(x, y, new Color(red, green, blue).getRGB()); } // close the y loop }// close the x loop // Write the adjusted image back out to a new file ImageIO.write(image, "JPEG", new File("ncstate-brightened.jpg")); System.out .println("Image adjusted and written to ncstate-brightened.jpg."); } } I am not supposed to edit ANYTHING in the main method. I can, however, edit anything outside of that. I tried adding +adjustBy to the return statement, but it either does nothing to the image or tells me that the "Color parameter outside of expected range:" There are not hints or help on the assignment of what I am supposed to do. Can anyone else help?
-
Answer:
C Tutorials-http://turboc.info/
roushu_w... at Yahoo! Answers Visit the source
Related Q & A:
- How to Code Encryption Algorithm in Java?Best solution by code2learn.com
- how to close the applet in java code?Best solution by Stack Overflow
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- how to Create a Java Package from MATLAB Code?Best solution by Stack Overflow
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.