我有一个要在 Java 中完成的任务,我这辈子都想不通。我应该使用 Graphics2D 和 Java.AWT。在 x 轴和 y 轴上镜像图像。
当前代码是:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
public class DrawingImages
{
private Picture newCanvas = null;
private Graphics g = null;
private Graphics2D g2 = null;
private Picture pic1 = null;
private Picture pic2 = null;
private Color color = null;
private Pixel sourcePixel, targetPixel = null;
private Color sourceColor, targetColor = null;
DrawingImages(Picture canv, Color col)
{
Picture sourcePicture = new Picture("WashingtonMonument.jpg");
newCanvas = canv;
newCanvas.setAllPixelsToAColor(Color.BLACK);
for(int y = sourcePicture.getHeight()-1; y >0; y=y-1)
{
for(int x = sourcePicture.getWidth() - 1; x > 0; x = x - 1)
{
sourcePixel = sourcePicture.getPixel(x,y);
sourceColor = sourcePixel.getColor();
targetPixel = newCanvas.getPixel(x+sourcePicture.getWidth() -1,y+sourcePicture.getHeight()- 1);
targetPixel.setColor(sourceColor);
}
}
g = newCanvas.getGraphics();
g2 = (Graphics2D)g;
}
}