2009-04-27 79 views
4

任何知道如何在Java中重新創建交叉散列紋理?下面的C#代碼顯示瞭如何在.NET框架中完成此操作。 Java片段很近,但我無法正確地將線條旋轉45度。Java交叉陰影紋理

C#

HatchBrush crossHatch = 
     new HatchBrush(HatchStyle.Cross, somecolor, somecolor); 

的Java

BufferedImage bufferedImage = 
     new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB); 

Graphics2D g2 = bufferedImage.createGraphics(); 

g2.setColor(Color.BLUE); 
g2.fillRect(0, 0, 5, 5); 
g2.setColor(pinColor); 
g2.fillOval(0, 0, 5, 5); 

// paint with the texturing brush 
Rectangle2D rect = new Rectangle2D.Double(0, 0, 5, 5); 
g2d.setPaint(new TexturePaint(bufferedImage, rect)); 
g2d.fill(shape); 

在此先感謝。

回答

9

下面是一個應該劃格在5個像素的間隔:

BufferedImage bufferedImage = 
     new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB); 

Graphics2D g2 = bufferedImage.createGraphics(); 
g2.setColor(backColor); 
g2.fillRect(0, 0, 5, 5); 
g2.setColor(stripeColor); 
g2.drawLine(0, 0, 5, 5); // \ 
g2.drawLine(0, 5, 5, 0); ///

// paint with the texturing brush 
Rectangle2D rect = new Rectangle2D.Double(0, 0, 5, 5); 
g2d.setPaint(new TexturePaint(bufferedImage, rect)); 
g2d.fill(shape);