2015-06-11 23 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点和映射剪的序列。

虽然只有链接的答案通常皱起了眉头,但我不想复制粘贴并撕掉一个完全解释的答案并用我的话填充他的单词。