2012-04-01 29 views
1

我想获得BufferedImage的子图像,然后使用此子图像替换原始的BufferedImage,以实现基于用户指定选择的缩放功能。但是,当我将subImage重绘到原始图像上时,子图像的底部未显示。我不知道为什么。我想知道是否有人可以发现任何明显的缺点!?!放大BufferedImage的特定部分

private void zoomImage(int x1, int x2, int y1, int y2){ 
    BufferedImage subImage = originalImage.getSubimage(x1, y1, x2-x1, y2-y1); 
    Graphics2D graphics2D = (Graphics2D) originalImage.getGraphics(); 
    graphics2D.drawImage(subImage, 0, 0, 600, 400, 0,0, x2-x1,y2-y1, null); 
    // clean up 
    graphics2D.dispose(); 
} 

我也想知道是否有实现在特定矩形选区放大和使用部分放大取代原来的图像更好的办法。

回答

0

应该注意的是,子图像的大小不应超过原始图像的宽度和高度。 例如,如果originalimage.width=600orignalimage.height=800那么可以创建大小应为subimage.horizentalorigin+subimage.width<=600subimage.veticalorigin+subimage.height<=800的子图像。否则,在图像的角落总会出现黑影。

  • subimage.horizentalorigin=x1
  • subimage.verticalorigin=x2
  • subimage.width=y1
  • 你的情况特别subimage.height=y2

其余的计算你做不同算法对算法.....