如何剪切图像并将其保存到另一张图像?
答案 0 :(得分:10)
如果src
是BufferedImage
,那么您可以从中剪切矩形(x1,y1)-(x2,y2)
并将其写入dst.png
,如下所示:
final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = dst.createGraphics();
g.drawImage(src, x1, y1, x2, y2, null);
g.dispose();
ImageIO.write(dst, "PNG", new FileOutputStream("dst.png"));