> hmm...
>
> how about using this link as a guide for helping me
> to answer my question?
>
> http://www.cs.umd.edu/class/summer2007/cmsc131/Project
> s/P3/proj3.html
How about asking a specific question instead of expecting us to study your homework assignment?
I would never ask for help if I wasn't so frigging confused.
I did the first two projects without any help btu no one I know knows Java so I am stuck going here as a last resort. i really do not know how to achieve any of the stuff I need to reconstruct a picture. I wanted help just reproducing the same pic as a full copy that is constructed pixel by pixel that also collects the color information . I can do the rest if I get this foothold.
I need to be able to:
Extract the data (width, height) of the original,
Extract data for each pixel (Red,blue,green, and position)
Translate it onto a new blank photograph
return the new full picture
From there I can do the manipulations necessary to construct the remaining scenarios.
> I would never ask for help if I wasn't so frigging
> confused.
>
> I did the first two projects without any help btu no
> one I know knows Java so I am stuck going here as a
> last resort. i really do not know how to achieve any
> of the stuff I need to reconstruct a picture. I
> wanted help just reproducing the same pic as a full
> copy that is constructed pixel by pixel that also
> collects the color information . I can do the rest if
> I get this foothold.
If you have no idea how to finish a school assignment which uses classes outside of the standard Java classes, this is not the place to ask questions: you should ask them to your teacher/professor or TA.
> I need to be able to:
>
> Extract the data (width, height) of the original,
> Extract data for each pixel (Red,blue,green, and
> position)
> Translate it onto a new blank photograph
> return the new full picture
>
> From there I can do the manipulations necessary to
> construct the remaining scenarios.
Have you studied the Pixel and Photograph apis like the assignment says? If so, what specific problem are you having using them?
(btw, this teacher's supposed to be teaching you how to manipulate images, but he uses jpg for cartoons and screenshots? blech)
> http://www.cs.umd.edu/class/summer2007/cmsc131/Projects/P3/doc/index.html
>
> it's mostly getters and setters actually
Can you use those getters and setters to do any of the following?
Extract the data (width, height) of the original,
Extract data for each pixel (Red,blue,green, and position)
Translate it onto a new blank photograph
return the new full picture
Extract data for each pixel (Red,blue,green, and position)->
Translate it onto a new blank photograph
that's my main problem... I think the rest is just minor confusion.
I'll show you what I have so far... it''s going to be messy but
public static Photograph copy(Photograph photo) {
Photograph copyPhoto = new Photograph(photo.getHeight(), photo.getWidth());
int xPix, yPix;
int xPixMax=photo.getHeight();
int yPixMax=photo.getWidth();
int red,blue,green;
Pixel pixel=new Pixel (red,blue,green);
for (xPix = 1; xPix <= xPixMax; xPix++){
for (yPix = 1; yPix <= yPixMax; yPix++){
green= photo.getGreen(xPix,yPix);
red= photo.getRed(xPix,yPix);
blue= photo.getBlue(xPix,yPix);
copyPhoto.setPixel(xPix,yPix,pixel);
}
}
return copyPhoto;
> Extract data for each pixel (Red,blue,green, and
> position)->
> Translate it onto a new blank photograph
>
>
> that's my main problem... I think the rest is just
> minor confusion.
>
> I'll show you what I have so far... it''s going to be
> messy but
Do you have a way of viewing the Photograph that method returns? If so you can verify it it's working correctly. If it isn't, then we need to know what's wrong with the results to help you fix it.
A couple basic mistakes:
1. The API states: (Photohgraph's getPixel):
Pixel at position (x, y) in the photograph. Note that the origin (0, 0) is located at the upper left corner of the photo.
so x and y coordinates start with 0, not the 1 in your code.
2. This will not work:
Pixel pixel=new Pixel (red,blue,green);
//later:
green= photo.getGreen(xPix,yPix);
red= photo.getRed(xPix,yPix);
blue= photo.getBlue(xPix,yPix);
copyPhoto.setPixel(xPix,yPix,pixel);
assigning to int variables red, green and blue will not change the state of pixel. You need to create a new Pixel object for every tuple of values.
Also: Photograph does not have getRed/getGreen/getBlue methods. Those are Pixel methods, so apply them to a Pixel object, not a Photograph object.
Message was edited by:
BigDaddyLoveHandles
public static Photograph copy(Photograph photo) {
Photograph copyPhoto = new Photograph(photo.getHeight(), photo.getWidth());
int xPix, yPix;
int xPixMax=photo.getHeight();
int yPixMax=photo.getWidth();
int red,blue,green;
Pixel pixel= new Pixel (red,blue,green);
Pixel copyPix= new Pixel (red,blue,green);
for (xPix = 0; xPix <= xPixMax; xPix++){
for (yPix = 0; yPix <= yPixMax; yPix++){
errorgreen= pixel.getGreen(xPix,yPix);
errorred= pixel.getRed(xPix,yPix);
errorblue= pixel.getBlue(xPix,yPix);
errorcopyPix(red, blue, green);
copyPhoto.setPixel(xPix,yPix,copyPix);
}
}
return copyPhoto;
public static Photograph copy(Photograph photo) {
Photograph copyPhoto = new Photograph(photo.getHeight(), photo.getWidth());
int xPix, yPix;
int xPixMax=photo.getHeight();
int yPixMax=photo.getWidth();
int red,blue,green;
Pixel pixel= new Pixel (red, blue, green); //this is the only remaining error right now.
for (xPix = 0; xPix <= xPixMax; xPix++){
for (yPix = 0; yPix <= yPixMax; yPix++){
photo.getPixel(xPix,yPix);
green=pixel.getGreen();
red= pixel.getRed();
blue= pixel.getBlue();
Pixel copyPix= new Pixel (red,blue,green);
copyPhoto.setPixel(xPix,yPix,copyPix);
}
}
return copyPhoto;
When you assign to a variable, that overwrites its previous value.
Then this:
Pixel pixel = new Pixel(red, green, blue); //assuming red, green and blue are initialized.
...
pixel= photo.getPixel(xPix,yPix);
Is the same as this:
Pixel pixel = null;
...
pixel= photo.getPixel(xPix,yPix);
Suggestion: define variable when you can give them a value:
Pixel pixel= photo.getPixel(xPix,yPix);
Do you see the difference?
cool, that fixed that part
but something is wrong with the overall thing
theoretically this should work for everything and no errors come up until I run it.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.IntegerInterleavedRaster.getDataElements(Unknown Source)
at java.awt.image.BufferedImage.getRGB(Unknown Source)
at photo.Photograph.getPixel(Photograph.java:73)
at editing.PhotoTools.copy(PhotoTools.java:30)
at photo.PhotoSystem.begin(PhotoSystem.java:60)
at editing.Driver.main(Driver.java:13)
> Coordinate out of bounds!
Looking at that stack trace, it's clear that you are calling getPixel with an x or y value that is out of bounds. Suppose you had this array:
double[] v = new double[size];
What for loop would you write to iterate over its elements? Then compare that answer to the code you wrote to iterate over the pixels in the Photograph.