import java.awt.Graphics2D; //导入方法依赖的package包/类 public static void renderTest(Graphics2D g2d, int w, int h) { g2d.setColor(Color.yellow); g2d.fillRect(0, 0, w, h); BufferedImage image = getTestImage(); // draw original image g2d.drawRenderedImage(image, null); // draw image with custom composite g2d.translate(175, 25); Composite currentComposite = g2d.getComposite(); g2d.setComposite(new TestComposite()); g2d.drawRenderedImage(image, null); g2d.setComposite(currentComposite); // draw image with XOR g2d.translate(175, 25); g2d.setXORMode(Color.red); g2d.drawRenderedImage(image, null); System.out.println("Painting is done..."); }
参考:https://vimsky.com/examples/detail/java-method-java.awt.Graphics2D.drawRenderedImage.html