java的BufferedImage类的getSubimage()方法的问题

2025-03-17 16:26:26
推荐回答(3个)
回答1:

getSubimage方法是进行图片裁剪。
举例:
public static void main(String[] args) {
try {
//从特定文件载入
BufferedImage bi = ImageIO.read(new File("c:\\test.jpg"));
bi.getSubimage(0, 0, 10, 10);//前两个值是坐标位置X、Y,后两个是长和宽
} catch (IOException e) {
e.printStackTrace();
}
}

回答2:

没有处理过,文档里说了共享同样的数据
Returns a subimage defined by a specified rectangular region.
The returned BufferedImage shares the same
data array as the original image.

回答3:

先保存一份 要用的时候,随时再拿来用