2015-06-11 63 views
0

我正在創建一個程序,我必須在水平和垂直方向上反射圖像。我創建了一個幾何形狀的圖像,但我很難弄清楚如何翻轉圖像。我想知道如果有人能幫助我,並告訴我該怎麼做來翻轉圖片。由於如何在java中反映圖像

到目前爲止我的代碼是:

import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.awt.Color; 

class DrawingDemoV3 
{ 
    Picture canvas = null; 
    Graphics g = null; 
    Graphics2D g2 = null; 

    DrawingDemoV3(int length, int height, Color color) 
    { 
     canvas = new Picture(length, height); 
     canvas.setAllPixelsToAColor(color); 
     g = canvas.getGraphics(); 
     g2 = (Graphics2D)g; 
     g2.setColor(color);  
    } 

    public void drawAFilledOval(Color color, int x1, int y1, int width, int height) 
    { 
     g2.setColor(color); 
     g2.fillOval(x1, y1, width, height); 
    } 

    public void drawARectangle(Color color, int x1, int y1, int width, int height) 
    { 
     g2.setColor(color); 
     g2.drawRect(x1, y1, width, height); 
    } 

    public void drawAFilledRectangle(Color color, int x1, int y1, int width, int height) 
    { 
     g2.setColor(color); 
     g2.fillRect(x1,y1, width, height); 
    } 

    public void drawALine(Color color, int x1, int y1, int x2, int y2) 
    { 
     g2.setColor(color); 
     g2.drawLine(x1,y1,x2,y2); 
    } 

    public Picture getDrawing() 
    { 
     return canvas; 
    } 
} 

public class DrawingDemoTesterV3 
{ 
    public static void main(String[] args) 
    { 
     DrawingDemoV3 drawing1 = new DrawingDemoV3(200, 200, Color.BLACK); 

     drawing1.drawAFilledRectangle(Color.PINK, 90, 0, 20, 200); 
     drawing1.drawAFilledRectangle(Color.PINK, 0, 90, 200, 20); 
     drawing1.drawARectangle(Color.CYAN, 40, 40, 120, 120); 
     drawing1.drawALine(Color.ORANGE, 0,0, 200, 200); 
     drawing1.drawALine(Color.ORANGE, 200,0, 0, 200); 
     drawing1.drawAFilledOval(Color.YELLOW, 80, 80, 38, 36); 

     Picture picture1 = drawing1.getDrawing(); 
     picture1.show(); 
    } 
} 
+0

我搜索了這個,並提出了一個主要的例子。你需要進一步提高你的谷歌技能。 – Adam

回答

0

Flipping/Reflection on an image.

的目標是使用Affine Transform用於翻譯,縮放,翻轉,旋轉,並應用到2D點和映射剪的序列。

雖然只有鏈接的答案通常皺起了眉頭,但我不想複製粘貼並撕掉一個完全解釋的答案並用我的話填充他的單詞。