如何在java中反映图像

时间:2015-06-11 14:16:25

标签: java image reflection graphics graphics2d

我正在创建一个程序,我必须水平和垂直地反映图像。我已经创建了一个几何形状的图像,但我很难弄清楚如何翻转我的图片。我想知道是否有人可以帮助我并告诉我该如何翻转图片。感谢

到目前为止我的代码是:

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();
    }
}

1 个答案:

答案 0 :(得分:0)

Flipping/Reflection on an image.

目标是将Affine Transform用于应用于2D点和映射的平移,缩放,翻转,旋转和剪切序列。

虽然链接只有答案通常不受欢迎,但我不想只是复制粘贴并撕掉一个完美解释的答案并填写他的话语。