This discussion is archived
1 Reply Latest reply: Jan 6, 2013 7:04 PM by DarrylBurke RSS

pixels and RGB values of a .png file

983185 Newbie
Currently Being Moderated

i started learning java last night and am trying to understand the java tutorials from
at the moment i am doing an exercise where i should load a .png file, which originally is dark, and edit some of the RGB values, in a way that i could clearly see the hidden image.

i think i am doing alright when it comes to loading an image and showing it, but i am failing at the process of reading the pixels and getting the RGB values.
that is what i have, so far:
    public class ImagePuzzle {  
        public void solveBlackPuzzle() {  
        Picture input = new Picture(FileChooser.pickAFile());  
        Picture output = null;  
        if (input != null) {  
             //  here i would grab the pixels, read their RGB values and change them.
            String directory = "/home/user/";    
            output.write(directory + "black-puzzle-solution.png");  
this is what i think would be in the commented part:
    method to decrease red 
    get the pixels;  
    define an integer that will work as a counter  
    for (int= 0; i < my pixels number; i++)  
    p = pixels; 
value = p.getRed();

now it should show the picture, with the red value changed...


when i manage to get the syntax correct, the code is compiled and it shows the open directory dialog, i choose an image, it shows me the image and nothing more happens.
otherwise i cant manage to have the correct syntax.
i understand my structure as
public Class 
public void solveBlackPuzzle
does it make sense to include the method i want inside public void solveBlackPuzzle? I have a class called Pixel, Picture and FileChooser.
If i try to create my Pixel object inside this part of the code, it tells me i am doing something illegal.
thanks in advance and kind regards.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points