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

    Default Making a picture Warhol Style

    I am trying to create a method so that in my Picture.java class that will create and return a new picture object, the new picture will be a grid layout with four versions of the picture. The four versions will be Grays, Reds, Blues, and Greens. Each version will contain the pixels that fit into that category, and there will be no overlap. It will look so the picture only has the pixels that are gray in the upper left hand corner, the picture of only the red pixels will be in the upper right hand corner, the picture with only the green pixels in the bottom left hand corner, and the reds the same way in the bottom right. The new picture will have twice the width and height, You need to see where each pixel belongs in order to know where to put them. Using an if/else if/else statement.

    so far all I have gotten is this : I am stuck, and I am having two errors I am not sure about. Anything will help.

    Java Code:
    public Picture componentLayout()
       {
       //Declare new picture
       Picture newPicture = new Picture(this.getWidth() * 2, this.getHeight()
    * 2);
       Pixel sourcePixel = null;
       Pixel targetPixel = null;
       int targetX = 0;
       int targetY = 0;
       // the redvalue of each pixel in the image
       int redValue=0;
       // The bluevalue of each pixel in the image
       int blueValue = 0;
       // the greenvalue of each pixel in the image
       int greenValue=0;
       Pixel pixelObj = null;
       Pixel[] pixelArray = this.getPixels();
       for (int index = 0; index < pixelArray.length; index++)
       {
         // Get the pixel at the current index from the array of pixels.
         pixelObj = pixelArray[index];
         // Get the blue value at the pixel.
         blueValue = pixelObj.getBlue();
         // Get the red value at the pixel.
         redValue = pixelObj.getRed();
         // Get the green value at the pixel
         greenValue = pixelObj.getGreen();
         int range = 0;
         //loops through x
         for (int x= 0; x < this.getWidth(); x++)
         {
           //loops through y
           for (int y = 0; y < this.getHeight(); y++)
           {
             //source pixels retrieved
             sourcePixel = this.getPixel(x,y);
             if (redValue > blueValue && greenValue)
             {
              targetPixel = this.getWidth()*2;
             }
    
    
           }
         }
    //return picture
         return newPicture;
       }
    
    }
    my errors are :

    2 errors found:
    File: C:\Documents and Settings\SEFCUMgr\My Documents\bookClasses\Picture.java [line: 115]
    Error: C:\Documents and Settings\SEFCUMgr\My Documents\bookClasses\Picture.java:115: operator && cannot be applied to boolean,int
    File: C:\Documents and Settings\SEFCUMgr\My Documents\bookClasses\Picture.java [line: 117]
    Error: C:\Documents and Settings\SEFCUMgr\My Documents\bookClasses\Picture.java:117: incompatible types
    found : int
    required: Pixel




    THANKS IN ADVANCE!

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Java Code:
             if (redValue > blueValue && greenValue)
             {
              targetPixel = this.getWidth()*2;
             }
    is causing you all the grief.

    1. What is "if (redValue > blueValue && greenValue)" supposed to mean? red greater than blue and greater than green? Then say "if (redValue > blueValue && redValue>greenValue)"

    2. targetPixel = this.getWidth()*2; - you can't do that, targetPixel is an Object, and this.getWidth()*2 is a number. Perhaps what you meant is "targetX = this.getWidth()*2"

  3. #3
    chick is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default

    once I change those 2 I still have an error stating I am missing a return statement, but I have a return statement.


    and do you happen to know how I can continue to finish this code.

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    count your braces...

  5. #5
    chick is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default

    but when I get rid of the bracket then it says that I reached the end while parsing. which doesnt make sense, cause all my brackets line up, and I dont know how to change it to make it so that the grays are seperated. if anyone can help me with that I would appreciate it as well.

Similar Threads

  1. Executing a jar double-click style in Linux
    By goodwillwins in forum AWT / Swing
    Replies: 24
    Last Post: 03-19-2011, 04:56 AM
  2. How to create a Warhol effect in an image.
    By racewithferrari in forum New To Java
    Replies: 12
    Last Post: 04-14-2010, 01:54 AM
  3. Long boolean coding style
    By Aldius in forum New To Java
    Replies: 10
    Last Post: 10-23-2009, 12:51 AM
  4. Cascading Style Sheets
    By smart in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-27-2008, 05:25 PM
  5. NetBeans-style Dockable-windows and toolbar?
    By jimm1 in forum Advanced Java
    Replies: 0
    Last Post: 01-31-2008, 08:41 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
  •