从java中的现有图像中剪切部分图像

目前在 Java工作,我希望能够使用鼠标指针坐标选择图像的一部分.然后,需要从现有图像中剪切所选区域,并用于创建新的单独图像.

就像关于如何去做的几点一样.谢谢.

解决方法

如果您希望用户能够“单击并拖动”以选择矩形,则需要实现 MouseMotionListener.请查看mouseDragged方法:

void mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged.

当你需要掌握子图像时,你只需使用

public BufferedImage getSubimage(int x,int y,int w,int h)
Returns a subimage defined by a specified rectangular region. The returned BufferedImage shares the same data array as the original image.

如果要将生成的图像保存到磁盘,建议您查看Saving a Generated Graphic to a PNG or JPEG File.

相关文章

摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
今天犯了个错:“接口变动,伤筋动骨,除非你确定只有你一个...
Writer :BYSocket(泥沙砖瓦浆木匠)微 博:BYSocket豆 瓣:...
本文目录 线程与多线程 线程的运行与创建 线程的状态 1 线程...