Results 1 to 6 of 6
  1. #1
    brandnew956 is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Angry Component Layout method help check my code!!

    **The code I have so far at the very bottom of the post** For my computer science class we are told to do a project which I will post below. My teacher has yet to discuss how to do this as he did the same with the last project and I'm getting very frustrated. Im not asking for somebody to do it for me, I am asking for help on the areas I dont understand. In the project it says we need to get red, blue, green and grayscale values and put them on a picture. (Theres a better description below). I know I need to get the red blue and green values then use if and else statements to assign them to their designated spots but I dont know how to get the different colors to different areas on the picture. I put the part I dont know hwo to do in bold. Any help will be greatly appreciated. Thanks!


    I ATTACHED WHAT THE FINAL PRODUCT SHOULD LOOK LIKE IN A PICTURE FILE*


    DESCRIPTION
    COMPONENTLAYOUT
    Create a new method:
    public Picture componentLayout() in Picture.java. This method will create and return a new picture object.
    The new picture should be a grid layout with four versions of the picture. The four versions will be Grays, Reds, Greens, and Blues. Each version will contain the pixels that fit in that category, and there will be no overlap. The layout will be as follows:

    Grays |Reds
    Greens| Blues

    The new picture will obviously have twice the width and twice the height as the original. You should check each pixel to see where it belongs.
    Use an if/else if/else statement. You should check for grayscale first.
    To determine if a pixel is grayscale:
    • Compute the intensity
    • Create the grayscale color of that pixel
    • Check if the color distance between that pixel and the grayscale color is less than 16
    After that, check for each of the other three regions. A pixel belongs in the red region if its red component is larger than green and blue. Similar for green and blue. Once you determine the region where a pixel belongs, copy it to the correct location in the new picture object. (Think about the x and y values)


    Introduction to Computer Science
    CSI201
    Spring 2010


    ASSIGNMENT 4
    EXAMPLE
    String fileName = ".../balloon.jpg";
    Picture original = new Picture(fileName);
    original.componentLayout().show();

    The origional picture is just a single picture of a balloon btw lol


    MY METHOD SO FAR


    //Component Layout method

    public Picture componentLayout()
    {

    //set all pixels to null
    Pixel sourcePixel = null;
    Pixel targetPixel = null;
    Pixel cPixel = null;

    {
    //set up new picture that will be big enough to fit all 4 edited pictures
    Picture newSizePic = new Picture(this.getWidth()*2, this.getHeight()*2);

    {
    //create a loop that goes through all the x's and y's
    for (int x = 0; x < getWidth(); x++)
    for (int y = 0; y < getHeight(); y++)

    {
    //get color values of the picture
    int redValue = pixelObj.getRed;
    int blueValue = pixelObj.getBlue;
    int greenValue = pixelObj.getGreen;
    }
    //if and else statements to check where colors go
    {
    //then image goes to grayscale area
    if (redValue == blueValue && blueValue == greenValue && redValue == greenValue)
    this.getPixel(x,y);
    //then it goes to the red area
    else if (redValue > blueValue+greenValue)
    this.getPixel(x,y);
    //then it goes to the blue area
    else if (blueValue > redValue+greenValue)
    this.getPixel(x,y);
    //then it goes to the green area
    else if (greenValue > redValue+blueValue)
    this.getPixel(x,y);
    }
    {
    return newSizePic;
    }
    }
    }
    }
    }
    Attached Thumbnails Attached Thumbnails Component Layout method help!!!-compsci.jpg  
    Last edited by brandnew956; 04-12-2010 at 08:56 PM. Reason: I put in what code I have already

  2. #2
    brandnew956 is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    anybody?????

  3. #3
    mchammer11 is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    that looks really easy

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    You can use GridLayout manager as

    Java Code:
    GridLayout layout=new GridLayout(2,2);

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Where do you do this?

    To determine if a pixel is grayscale:
    • Compute the intensity
    • Create the grayscale color of that pixel
    • Check if the color distance between that pixel and the grayscale color is less than 16
    Instead I see you do this:
    Java Code:
    if (redValue == blueValue && blueValue == greenValue && redValue == greenValue) {
    which will only be true if a color is exactly gray, which is not what the requirements ask you to do.

  6. #6
    flychild is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Where do you do this?



    Instead I see you do this:
    Java Code:
    if (redValue == blueValue && blueValue == greenValue && redValue == greenValue) {
    which will only be true if a color is exactly gray, which is not what the requirements ask you to do.
    so what is the proper way to do this?

Similar Threads

  1. Edit layout Layout please help me
    By manhtungtnk28@gmail.com in forum New To Java
    Replies: 4
    Last Post: 11-23-2009, 08:41 AM
  2. Border Layout
    By mark-mlt in forum Java Applets
    Replies: 5
    Last Post: 05-12-2008, 09:48 AM
  3. Help with Grid Layout
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:03 PM
  4. Use the Layout in java
    By lenny in forum AWT / Swing
    Replies: 2
    Last Post: 07-26-2007, 07:20 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
  •