Results 1 to 3 of 3
Thread: How do I flip this image?
- 11-08-2012, 09:00 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
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.
Java 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, 11:26 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-08-2012, 08:30 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Flip int value(1234 becomes 4321)
By Pojahn_M in forum New To JavaReplies: 2Last Post: 09-27-2012, 11:47 PM -
Flip Pictures on DrJava
By siddanth1 in forum New To JavaReplies: 2Last Post: 02-10-2012, 02:08 AM -
coin flip program
By chandrasekhar.melam in forum New To JavaReplies: 5Last Post: 09-26-2011, 05:30 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


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks