Results 1 to 2 of 2
- 05-11-2011, 12:59 AM #1
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
How to Copy and Flip a Picture Horizontally
Hello,
I am working on a class that flips a picture on its horizontal axis.
I know that I have to copy the picture and then use the copy to help flip the picture, however I am unsure of what is going wrong.
Any help would be much appreciated.
Thanks,
Tec
class FlipHorizontally implements ActionListener {
public void actionPerformed (ActionEvent e) {
int imageWidth = picture.getWidth();
int imageHeight = picture.getHeight();
Picture copy = new Picture(picture.getWidth(), picture.getHeight());
copy.drawPicture(0,0, picture);
for (int x = 0; x < picture.getWidth(); x++) {
for (int y = 0; y < picture.getHeight(); y++) {
int red = copy.getPixelRed(x,y);
int green = copy.getPixelGreen(x,y);
int blue = copy.getPixelBlue(x,y);
picture.setPixelRed(imageWidth-x, y, red);
picture.setPixelGreen(imageWidth-x, y, green);
picture.setPixelBlue(imageWidth-x, y, blue);
}
}
picture.display();
}
}
- 05-11-2011, 01:47 AM #2
Your code uses classes that are not a part of the JDK, s it's well nigh impossible to offer any meaningful advice.
If you want to learn to use the relevant JDK classes, go through this tutorial:
Trail: 2D Graphics (The Java™ Tutorials)
db
Similar Threads
-
How can i make this JScrollPane scroll horizontally?
By ozzyman in forum AWT / SwingReplies: 1Last Post: 04-05-2011, 12:12 PM -
I want the output to be apper HORIZONTALLY
By o0oNorao0o in forum New To JavaReplies: 8Last Post: 01-21-2010, 12:24 PM -
Othello/Reversi flip checkers
By chielt in forum Java AppletsReplies: 10Last Post: 01-02-2010, 11:25 PM -
Random coin flip application
By Boomer1 in forum New To JavaReplies: 8Last Post: 12-18-2009, 02:57 AM -
How to duplicat drawOval horizontally?
By ntagrafix in forum AWT / SwingReplies: 1Last Post: 12-03-2009, 09:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks