How to cut and save a rectangle from an image?

How to cut an image and save it to another image?

+3
source share
1 answer

If srcis BufferedImage, you can cut a rectangle from it (x1,y1)-(x2,y2)and write it in the dst.pngfollowing way:

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"));
+10
source

Source: https://habr.com/ru/post/1769597/


All Articles