如何从图像中切出并保存矩形? [英] How to cut out and save a rectangle from an image?

查看:82
本文介绍了如何从图像中切出并保存矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何剪切图像并将其保存到其他图像?

How can cut the image and save it block to another image?

推荐答案

如果srcBufferedImage,则可以从中切出矩形(x1,y1)-(x2,y2)并将其写到dst.png中,如下所示:

If src is a BufferedImage, then you can cut the rectangle (x1,y1)-(x2,y2) from it and write that to dst.png like this:

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"));

这篇关于如何从图像中切出并保存矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆