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

The following examples show how to use java.awt.Graphics2D#copyArea() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
Source Project: dsworkbench   File: NoteLayerRenderer.java    License: Apache License 2.0 6 votes vote down vote up
private void renderNoteField(Village v, HashMap<Village, List<Note>> pNoteMap, int row, int col, int pFieldWidth, int pFieldHeight, int pCopyPosition, Graphics2D g2d) {
    if (v != null && v.isVisibleOnMap()) {
        List<Note> notes = pNoteMap.get(v);//NoteManager.getSingleton().getNotesForVillage(v);
        if (notes == null || notes.isEmpty()) {
            return;
        }
        int half = notes.size() / 2;
        int dx = -half * 2;
        int dy = -half * 2;

        //render notes
        for (Note n : notes) {
            int noteX = (int) Math.floor((double) col * pFieldWidth + pFieldWidth / 2.0 - 10);
            int noteY = (int) Math.floor((double) row * pFieldHeight + pFieldHeight / 2.0 - 23);
            int noteIcon = n.getMapMarker();
            if (noteIcon != -1) {
                g2d.copyArea(noteIcon * 32, pCopyPosition + 68, 32, 32, noteX + dx - noteIcon * 32, noteY + dy - pCopyPosition - 68);
                dx += 2;
                dy += 2;
            }
        }
    }
}
 
Example 11
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 12
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 13
Source Project: pumpernickel   File: VectorImageTest.java    License: MIT License 5 votes vote down vote up
public void testCopyArea() throws Exception {
	RenderTest t2 = new RenderTest() {

		@Override
		public void paint(Graphics2D g) {
			g.setPaint(Color.red);
			g.fill(new Triangle(0, 0, 100, 100).shape);
			g.copyArea(25, 25, 50, 50, 30, 30);
		}

	};
	t2.test();
}
 
Example 14
Source Project: dsworkbench   File: MapLayerRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private void renderMarkerField(Village v, int row, int col, int pFieldWidth, int pFieldHeight, double zoom, boolean useDecoration, Graphics2D g2d) {
    int tribeId = -666;
    BufferedImage sprite = null;
    Rectangle copyRect = null;
    boolean showBarbarian = GlobalOptions.getProperties().getBoolean("show.barbarian");
    Village currentUserVillage = DSWorkbenchMainFrame.getSingleton().getCurrentUserVillage();

    if (v != null && (!v.getTribe().equals(Barbarians.getSingleton()) || showBarbarian)) {
        v.setVisibleOnMap(true);
        tribeId = v.getTribeID();
        copyRect = renderedMarkerBounds.get(tribeId);
        if (copyRect == null) {
            sprite = getMarker(v);
        }
    } else {
        if (v != null) {
            v.setVisibleOnMap(false);
        }
        return;
    }

    //render sprite or copy area if sprite is null
    if (sprite != null) {
        //render sprite
        AffineTransform t = AffineTransform.getTranslateInstance(col * pFieldWidth, row * pFieldHeight);
        t.scale(1.0 / zoom, 1.0 / zoom);
        g2d.drawRenderedImage(sprite, t);
        if (currentUserVillage == null || !v.equals(currentUserVillage)) {
            renderedMarkerBounds.put(tribeId, new Rectangle(col * pFieldWidth, row * pFieldHeight, pFieldWidth, pFieldHeight));
        }
        sprite.flush();
    } else if (copyRect != null) {
        g2d.copyArea(copyRect.x, copyRect.y, copyRect.width, copyRect.height, col * pFieldWidth - copyRect.x, row * pFieldHeight - copyRect.y);
    }
}
 
Example 15
private static BufferedImage fromSkin(ServerListPlusCore core, URL url, boolean helm) throws IOException {
    BufferedImage skin = fromURL(core, url);
    if (helm && !isSolidColor(skin, HELM_X, HELM_Y, HEAD_SIZE, HEAD_SIZE)) {
        Graphics2D g = skin.createGraphics();
        g.copyArea(HELM_X, HELM_Y, HEAD_SIZE, HEAD_SIZE, HEAD_X - HELM_X, HEAD_Y - HELM_Y);
        g.dispose();
    }

    return skin.getSubimage(HEAD_X, HEAD_Y, HEAD_SIZE, HEAD_SIZE);
}
 
Example 16
Source Project: cosmic   File: CopyRect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void paint(final BufferedImage image, final Graphics2D graphics) {
    graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
}
 
Example 17
Source Project: pumpernickel   File: CopyAreaOperation.java    License: MIT License 4 votes vote down vote up
@Override
protected void paintOperation(Graphics2D g) {
	Rectangle r = getSourceRect();
	g.copyArea(r.x, r.y, r.width, r.height, getDX(), getDY());
}
 
Example 18
Source Project: dsworkbench   File: MapLayerRenderer.java    License: Apache License 2.0 4 votes vote down vote up
private void renderVillageField(Village v,
        int row,
        int col,
        int globalRow,
        int globalCol,
        int pFieldWidth,
        int pFieldHeight,
        double zoom,
        boolean useDecoration,
        boolean showBarbarian,
        boolean markedOnly,
        Graphics2D g2d) {
    Rectangle copyRect = null;
    int textureId = -1;
    BufferedImage sprite = null;

    // Marker villageMarker = MarkerManager.getSingleton().getMarker(v);
    if (v != null
            && !(v.getTribe().equals(Barbarians.getSingleton()) && !showBarbarian) // && !(villageMarker == null && markedOnly && !v.getTribe().getName().equals(GlobalOptions.getSelectedProfile().getTribeName()))
            ) {
        //village field that has to be rendered
        v.setVisibleOnMap(true);
        if (GlobalOptions.getSkin().isMinimapSkin()) {
            textureId = Skin.ID_V1;
        } else {
            textureId = v.getGraphicsType();
        }
        copyRect = renderedSpriteBounds.get(textureId);
        if (copyRect == null) {
            sprite = GlobalOptions.getSkin().getCachedImage(textureId, zoom);
        }
    } else {
        if (v != null) {
            v.setVisibleOnMap(false);
        }
        if (useDecoration) {
            textureId = WorldDecorationHolder.getTextureId(globalCol, globalRow) + 100;
        } else {
            textureId = Skin.ID_DEFAULT_UNDERGROUND;
        }
        copyRect = renderedSpriteBounds.get(textureId);
        if (copyRect == null && useDecoration) {
            sprite = WorldDecorationHolder.getCachedImage(globalCol, globalRow, zoom);
        } else if (copyRect == null && !useDecoration) {
            sprite = GlobalOptions.getSkin().getCachedImage(textureId, zoom);
        }
    }

    //render sprite or copy area if sprite is null
    int posX = col * pFieldWidth;
    int posY = row * pFieldHeight;
    if (sprite != null) {
        //render sprite
        if (bMarkOnTop) {
            g2d.setColor(Color.BLACK);
            g2d.fillRect(posX, posY, pFieldWidth, pFieldHeight);
        }
        g2d.drawImage(sprite, posX, posY, null);
        renderedSpriteBounds.put(textureId, new Rectangle(posX, posY, pFieldWidth, pFieldHeight));
    } else if (copyRect != null) {
        //copy from copy rect
        g2d.copyArea(copyRect.x, copyRect.y, copyRect.width, copyRect.height, posX - copyRect.x, posY - copyRect.y);
    }
}
 
Example 19
Source Project: cloudstack   File: CopyRect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void paint(BufferedImage image, Graphics2D graphics) {
    graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
}
 
Example 20
Source Project: whyline   File: CopyAreaEvent.java    License: MIT License 2 votes vote down vote up
public void paint(Graphics2D g) {

	g.copyArea(getX(), getY(), getWidth(), getHeight(), getDX(), getDY());		

}