2011-02-14 78 views

回答

0

基本上,你需要做的是:

  1. 创建一个BufferedImage,并用图形链接它反对
  2. 设置裁剪区域
  3. 绘制到此Graphics对象
  4. 在应用过滤器BufferedImage object

In pseudocode:

private BufferedImage bufferedImage = new BufferedImage() 
private Graphics2D graphics = bufferedImage.createGraphics() 

void paint(Graphics2D input) { 
    graphics.clip(selectionArea.getShape()) 
    upperCanvas.paint(graphics) 

    BufferedImageOp op 
    bufferedImage = op.filter(bufferedImage, new BufferedImage()) 

    input.drawImage(bufferedImage) 
} 

对于应用过滤器,见java.awt.image

正如你可以看到,这可以可以在Java2D的完成,但API是相当复杂的。如果你有兴趣,我可以建议纸浆作为替代框架。它包含几个预定义的过滤器和一个用于应用它们的单行API。请参阅demo。还包括一个Java2DSprite类,以便在pulpcore和java2d之间移植。