Java Code Examples for java.awt.Graphics2D#copyArea()
The following examples show how to use
java.awt.Graphics2D#copyArea() .
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
Source File: ScaledCopyArea.java From TencentKona-8 with GNU General Public License v2.0 | 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
Source File: ScaledCopyArea.java From jdk8u60 with GNU General Public License v2.0 | 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 3
Source File: ScaledCopyArea.java From openjdk-jdk8u with GNU General Public License v2.0 | 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 4
Source File: ScaledCopyArea.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 5
Source File: ScaledCopyArea.java From openjdk-jdk9 with GNU General Public License v2.0 | 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 6
Source File: ScaledCopyArea.java From jdk8u-jdk with GNU General Public License v2.0 | 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 7
Source File: ScaledCopyArea.java From dragonwell8_jdk with GNU General Public License v2.0 | 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 8
Source File: ScaledCopyArea.java From hottub with GNU General Public License v2.0 | 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 9
Source File: ScaledCopyArea.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 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 10
Source File: ScaledCopyArea.java From jdk8u-jdk with GNU General Public License v2.0 | 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 11
Source File: NoteLayerRenderer.java From dsworkbench with Apache License 2.0 | 6 votes |
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 12
Source File: ScaledCopyArea.java From jdk8u_jdk with GNU General Public License v2.0 | 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 13
Source File: FaviconHelper.java From ServerListPlus with GNU General Public License v3.0 | 5 votes |
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 14
Source File: MapLayerRenderer.java From dsworkbench with Apache License 2.0 | 5 votes |
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
Source File: VectorImageTest.java From pumpernickel with MIT License | 5 votes |
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 16
Source File: MapLayerRenderer.java From dsworkbench with Apache License 2.0 | 4 votes |
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 17
Source File: CopyAreaOperation.java From pumpernickel with MIT License | 4 votes |
@Override protected void paintOperation(Graphics2D g) { Rectangle r = getSourceRect(); g.copyArea(r.x, r.y, r.width, r.height, getDX(), getDY()); }
Example 18
Source File: CopyRect.java From cosmic with Apache License 2.0 | 4 votes |
@Override public void paint(final BufferedImage image, final Graphics2D graphics) { graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY); }
Example 19
Source File: CopyRect.java From cloudstack with Apache License 2.0 | 4 votes |
@Override public void paint(BufferedImage image, Graphics2D graphics) { graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY); }
Example 20
Source File: CopyAreaEvent.java From whyline with MIT License | 2 votes |
public void paint(Graphics2D g) { g.copyArea(getX(), getY(), getWidth(), getHeight(), getDX(), getDY()); }