Java Code Examples for java.awt.Graphics2D.copyArea()

The following are Jave code examples for showing how to use copyArea() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jdk8u-jdk   File: ScaledCopyArea.java   Source Code and License Vote up 6 votes
public static void main(final String[] args) {
    final BufferedImage bi = new BufferedImage(100, 300,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = bi.createGraphics();
    g.scale(2, 2);
    g.setColor(Color.RED);
    g.fillRect(0, 0, 100, 300);
    g.setColor(Color.GREEN);
    g.fillRect(0, 100, 100, 100);
    g.copyArea(0, 100, 100, 100, 0, -100);
    g.dispose();
    for (int x = 0; x < 100; ++x) {
        for (int y = 0; y < 100; ++y) {
            final int actual = bi.getRGB(x, y);
            final int exp = Color.GREEN.getRGB();
            if (actual != exp) {
                System.err.println("Expected:" + Integer.toHexString(exp));
                System.err.println("Actual:" + Integer.toHexString(actual));
                throw new RuntimeException("Test " + "failed");
            }
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: ScaledCopyArea.java   Source Code and License Vote up 6 votes
public static void main(final String[] args) {
    final BufferedImage bi = new BufferedImage(100, 300,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = bi.createGraphics();
    g.scale(2, 2);
    g.setColor(Color.RED);
    g.fillRect(0, 0, 100, 300);
    g.setColor(Color.GREEN);
    g.fillRect(0, 100, 100, 100);
    g.copyArea(0, 100, 100, 100, 0, -100);
    g.dispose();
    for (int x = 0; x < 100; ++x) {
        for (int y = 0; y < 100; ++y) {
            final int actual = bi.getRGB(x, y);
            final int exp = Color.GREEN.getRGB();
            if (actual != exp) {
                System.err.println("Expected:" + Integer.toHexString(exp));
                System.err.println("Actual:" + Integer.toHexString(actual));
                throw new RuntimeException("Test " + "failed");
            }
        }
    }
}