java.awt.Graphics2D#copyArea ( )源码实例Demo

下面列出了java.awt.Graphics2D#copyArea ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码2 项目: TencentKona-8   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码3 项目: jdk8u60   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码6 项目: openjdk-jdk9   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码7 项目: jdk8u-jdk   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码8 项目: hottub   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码9 项目: jdk8u_jdk   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码10 项目: dsworkbench   文件: NoteLayerRenderer.java
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;
            }
        }
    }
}
 
源代码11 项目: jdk8u-jdk   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码12 项目: jdk8u-dev-jdk   文件: ScaledCopyArea.java
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");
            }
        }
    }
}
 
源代码13 项目: pumpernickel   文件: VectorImageTest.java
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();
}
 
源代码14 项目: dsworkbench   文件: MapLayerRenderer.java
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);
    }
}
 
源代码15 项目: ServerListPlus   文件: FaviconHelper.java
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);
}
 
源代码16 项目: cosmic   文件: CopyRect.java
@Override
public void paint(final BufferedImage image, final Graphics2D graphics) {
    graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
}
 
源代码17 项目: pumpernickel   文件: CopyAreaOperation.java
@Override
protected void paintOperation(Graphics2D g) {
	Rectangle r = getSourceRect();
	g.copyArea(r.x, r.y, r.width, r.height, getDX(), getDY());
}
 
源代码18 项目: dsworkbench   文件: MapLayerRenderer.java
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);
    }
}
 
源代码19 项目: cloudstack   文件: CopyRect.java
@Override
public void paint(BufferedImage image, Graphics2D graphics) {
    graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
}
 
源代码20 项目: whyline   文件: CopyAreaEvent.java
public void paint(Graphics2D g) {

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

}