Java 如何使创建的图像在较大的画布中使用

Java 如何使创建的图像在较大的画布中使用,java,image,graphics,graphics2d,java-canvas,Java,Image,Graphics,Graphics2d,Java Canvas,对于我正在编写的代码。我做了一个小设计。我能够,使用代码,我必须使设计成为一个形象。但是当我尝试重用图像时,我的代码没有发生任何变化 我如何制作它,以便我的代码将它制作的图像放入一个更大的画布中,以便最终可以多次翻转图像?我的代码感觉有点凌乱,我认为第一种方法可以防止代码变大,但我不确定。目前,我只能使代码使设计成为一个形象。这就是我所拥有的: import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Color;

对于我正在编写的代码。我做了一个小设计。我能够,使用代码,我必须使设计成为一个形象。但是当我尝试重用图像时,我的代码没有发生任何变化

我如何制作它,以便我的代码将它制作的图像放入一个更大的画布中,以便最终可以多次翻转图像?我的代码感觉有点凌乱,我认为第一种方法可以防止代码变大,但我不确定。目前,我只能使代码使设计成为一个形象。这就是我所拥有的:

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

class PicturePattern {
    private Picture newCanvas1 = null;
    private Graphics g = null;
    private Graphics2D g2 = null;
    private Picture pic1 = null;
    private Picture pic2 = null;
    private Color color = null;

    PicturePattern(Picture canv, Picture p1) {
        newCanvas1 = canv;
        newCanvas1.setAllPixelsToAColor(Color.YELLOW);
        g = newCanvas1.getGraphics();
        g2 = (Graphics2D)g;  
        //pic1 = p1;
        //pic2 = p2;
        //color = col;
    }

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

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

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

    public Picture drawPicture() {
        //g2.setColor(Color.RED);
        //g2.fillOval(700, 30, 100, 100); 
        //g2.drawImage(pic1.getImage(),0, 0, null);
        //g2.drawImage(pic2.getImage(),45, 200, null);
        //g2.drawImage(pic2.getImage(),145, 100, null);
        //g2.drawImage(pic2.getImage(),145, 300, null);
        return newCanvas1;
    }   

}

public class PicturePatternTester1 {
    public static void main(String[] args) {
        Picture canvas = new Picture(200,200);

        Picture picture = new Picture("untitled.png");
        //Picture picture2 = new Picture("moon.jpg");
        PicturePattern draw = new PicturePattern(canvas, picture);
        draw.drawAFilledRectangle(0,0, 200, 200, Color.CYAN);
        draw.drawARectangle(50, 50, 150, 150, Color.RED);
        draw.drawALine(50, 50, 200, 200, Color.BLACK);
        draw.drawALine(200, 50, 50, 200, Color.BLACK);

        Picture picture1 = draw.drawPicture();
        picture1.show();
        picture1.write("pattern.jpg");

        /*
        Picture canvas1 = new Picture(800, 800);
        Picture picture2 = new Picture("pattern.jpg");
        PicturePattern draw1 = new PicturePattern(canvas1, picture2);
        */

        canvas = draw.drawPicture();

        canvas.show();
    }
}

谢谢你帮我修,谢谢你帮我修