import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

public final class FPDrawImageTest {

    static final Color LEFT_COLOR = new Color(255, 0, 0, 100);

    static final Color RIGHT_COLOR = new Color(0, 0, 255, 100);

    public static void main(final String[] args) throws Exception {
        int w = 7;
        int h = 7;
        // Init image
        BufferedImage img = new BufferedImage(70, 70, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, img.getWidth(), img.getHeight());

        //g.scale(1, 1);
        g.scale(1.5, 1.5);

        // FillRect
        g.setColor(LEFT_COLOR);
        g.fillRect(0, 0, w, h);

        g.setColor(RIGHT_COLOR);
        g.fillRect(w, 0, w, h);

        // MoveTo the next line
        g.translate(0, h + 3);

        // DrawImage
        BufferedImage img1 = createImage(w, h, LEFT_COLOR);
        g.setClip(0, 0, w, h);
        g.drawImage(img1, 0, 0, null);
        BufferedImage img2 = createImage(w, h, RIGHT_COLOR);
        g.setClip(w, 0, w, h);
        g.drawImage(img2, w, 0, null);
        g.setClip(null);

        // MoveTo the next line
        g.translate(0, h + 3);

        // DrawRect
        g.setColor(LEFT_COLOR);
        g.setClip(0, 0, w, h);
        g.drawRect(0, 0, w, h);
        g.setColor(RIGHT_COLOR);
        g.setClip(w, 0, w, h);
        g.drawRect(w, 0, w, h);

        g.dispose();

        ImageIO.write(img, "png", new File("two-images-clip-s150.png"));
    }

    private static BufferedImage createImage(int w, int h, Color c1) {
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();
        g.setColor(c1);
        g.fillRect(0, 0, w, h);
        return img;
    }
}
