如何使用图像填充以下矩形?任何人都可以帮助我吗?
public void paintComponent(Graphics g) {
setOpaque(false);
//Paint a filled rectangle at user's chosen point.
if (point != null) {
g.drawRect(0, 0,
rectWidth - 1, rectHeight - 1);
g.setColor(Color.yellow);
g.fillRect(1, 1,
rectWidth - 2, rectHeight - 2);
}}
我试过这段代码,但我找不到让它工作的方法:
File imageFile = new File("duck.jpg");
BufferedImage img;
Graphics2D graph = img.createGraphics();
graph.setColor(Color.BLACK);
graph.fill(new Rectangle(1, 2, rectWidth, rectHeight));
graph.dispose();
ImageIO.write(img, "jpg", new File("duck.jpg"));