我正在创建一个程序,其中我必须水平和垂直反映图像。我已经创建了一个几何形状的图像,但我很难弄清楚如何翻转我的图片。我想知道有没有人能帮我,告诉我怎么翻转一幅画。谢谢
到目前为止我的代码是:
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();
}
}发布于 2015-06-11 22:37:50
Flipping/Reflection on an image.
目标是将Affine Transform用于应用于二维点和映射的平移、缩放、翻转、旋转和剪切序列。
虽然只有链接的答案通常是不受欢迎的,但我不想只是复制粘贴并撕下一个完美解释的答案,然后用我的话填满他的话。
https://stackoverflow.com/questions/30783401
复制相似问题