使用下面的代码,我创建了1个边框(白色)。如何在白色边框上创建另一个边框(黑色)?
Image image = icon.getImage().getScaledInstance(widthX,heightY, Image.SCALE_SMOOTH);
icon.setImage(image);
int borderWidth = 1;
int spaceAroundIcon = 0;
Color borderColor = Color.WHITE;
BufferedImage bi = new BufferedImage(icon.getIconWidth() + (2 * borderWidth + 2 * spaceAroundIcon),
icon.getIconHeight() + (2 * borderWidth + 2 * spaceAroundIcon), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.setColor(borderColor);
g.drawImage(icon.getImage(), borderWidth + spaceAroundIcon, borderWidth + spaceAroundIcon, null);
BasicStroke stroke = new BasicStroke(5); //5 pixels wide g.getStroke();
g.setStroke(stroke);
g.drawRect(0, 0, bi.getWidth() - 1, bi.getHeight() - 1);
g.dispose();
最佳答案
更改颜色和笔触宽度,然后再次调用drawRect
!