2010-11-17 71 views
1

使用下面的代码,我创建了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(); 

回答

0

改变颜色和笔触宽度,并使用另一个电话drawRect

+0

谢谢dacwe :) – Jessy 2010-11-18 23:20:26