Results 1 to 9 of 9
  1. #1
    juddy1 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Smile Been stuck for days! any help would be appriciated...

    hey...

    Ok this is really starting to annoy me so please please help!

    I am trying to create a program which will take in a colour picture, turn it into an array of pixels covert those pixels into greyscale and put array back together again to make a greyscale copy of the first image.

    The code below is of the section i am stuck on. Basically i want to use color(int rgb) constructor to make a new object which i can pass my color pixel array into. i then want to create 3 new ints and make them equal to the red, green and blue values of my new Color.


    for (int i = 0; i < (width*height); i++){

    Color c = new Color(pixels*);

    int red = getRed();
    int green = getGreen();
    int Blue = getBlue();
    }

    *the array of color pixels.

    Im new so please be gentle!

    cheers

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    10

    Default

    Study the java image io classes, or emulate an image with a two dimensional array of a placeholder class you write yourself.

    Bring your lunch, your gonna be awhile before you can do Color.getRed() and so on.

    Graphics is rather advanced. I suggest ( if you need gentle ) move to some other simplified program such as hello world or develope simple array skills before working on what you have here.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    juddy1 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    thanks for the reply... done a little more work on it now got it to compile but instead of a greyscale image being returned i get a black image....

    my code is as follows:

    class SaveGreyMenuListnr implements ActionListener {

    private ImagePanel panel = null;

    SaveGreyMenuListnr (ImagePanel pn) {

    panel = pn;

    }

    public void actionPerformed (ActionEvent ae) {


    Image displayed = panel.getDisplayImage();

    int width = displayed.getWidth(panel);
    int height = displayed.getHeight(panel);

    int pixels[] = new int[width*height];



    PixelGrabber pg = new PixelGrabber(displayed, 0, height, width, height, pixels, 0, width);


    try{

    pg.grabPixels();


    } catch (InterruptedException e) {


    System.err.println("interrupted waiting for pixels");

    }

    for (int i = 0; i < (width*height); i++){

    Color myColor = new Color(pixels[i]);


    int Red = myColor.getRed();

    int Green = myColor.getGreen();

    int Blue = myColor.getBlue();

    double temp = 0.56 * (double)Green + 0.33 *(double) Red + 0.11 *(double) Blue;
    myColor = new Color((int)temp,(int)temp,(int)temp);
    int compressedInt = myColor.getRGB();

    pixels[i] = compressedInt;

    }


    Image image = panel.getToolkit().createImage(new MemoryImageSource(width,height,pixels,0,width));

    panel.setDisplayImage(image);
    panel.repaint();
    }

    }


    All i can think of is that when im using the getRed,getGreen and getBlue methods they are returning 0 values.

    I tested this by putting a System.out.println(Red); and it just returned a large number of 0's...

    Im sure its something easy ive missed if anyone has any bright ideas i would be very grateful!

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    10

    Default

    Where are you getting the image from? Why is there ActionListener / ActionPerformed?

    Code is a little messy, but that is common on beginner code, what we need to do here is grasp where the image comes from, pass that to PixelGrabber, no?

    I want to do something like this in my own program, such blunderous code does not bother me - what we need to establish first is where the graphic is coming from......
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  5. #5
    meth is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    hi, im referring to ur code:

    int pixels[] = new int[width*height];
    .
    .
    for (int i = 0; i < (width*height); i++){
    Color myColor = new Color(pixels[i]);
    .
    .
    .
    myColor = new Color((int)temp,(int)temp,(int)temp);
    int compressedInt = myColor.getRGB();
    pixels[i] = compressedInt; }

    can u pls explain to me wat does the above codes for? thx in advance.

    }

  6. #6
    meth is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    hi, im referring to ur code:

    int pixels[] = new int[width*height];
    .
    .
    for (int i = 0; i < (width*height); i++){
    Color myColor = new Color(pixels[i]);
    .
    .
    .
    myColor = new Color((int)temp,(int)temp,(int)temp);
    int compressedInt = myColor.getRGB();
    pixels[i] = compressedInt; }

    can u pls explain to me wat does the above codes for? thx in advance.

    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,299
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by meth View Post
    hi, im referring to ur code:
    @Meth: erm, this thread is more than two years old; it is stone dead.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  8. #8
    meth is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    lol i know. i was juz replying here coz i dunno wanna make a double post. but i posted mine anyway, would u pls be kind enogh to help me sir? how to count frequency of the color? ur help is appreciated.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    28

Similar Threads

  1. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 03:56 AM
  2. [SOLVED] Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 12
    Last Post: 09-23-2008, 03:18 AM
  3. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM
  4. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:06 AM
  5. I am completely stuck
    By jpnym15 in forum New To Java
    Replies: 2
    Last Post: 11-14-2007, 07:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •