How do I flip this image?

• 11-08-2012, 10:00 AM
antnas
How do I flip this image?
I made code so that I can copy a smaller picture into a bigger picture which is working but I need to add code to make it flip 180 degrees and I do not know how to go about that.
This is my code so far it picks up every pixel in the picture.
Code:

public void copyInto(int xWhere, int yWhere, Picture flower)
{
for(int x = 0; x < flower.getWidth(); x++)
{
for(int y = 0; y < flower.getHeight(); y++)
{
int red;
int green;
int blue;
red = flower.getPixel(x,y).getRed();
green = flower.getPixel(x,y).getGreen();
blue = flower.getPixel(x,y).getBlue();
this.getPixel(xWhere + x, yWhere + y).setColor(new Color(red, green, blue) );
}
}
}

• 11-08-2012, 12:26 PM
JosAH
Re: How do I flip this image?
The solution is in the last line of your code: now it puts a pixel at (x,y) (flower coordinates) at (xWhere+x, yWhere+y) (image coordinates). If you stick it at position (xWhere+flower.getWidth()-1-x, yWhere+y) you have flipped your flower over a vertical axis; flipping over a horizontal axis is left as an exercise for the reader ;-)

kind regards,

Jos
• 11-08-2012, 09:30 PM
antnas
Re: How do I flip this image?
This helped a bunch! Thank you!