x - 指定矩形区域左上角的 X 坐标
y - 指定矩形区域左上角的 Y 坐标
w - 指定矩形区域的宽度
h - 指定矩形区域的高度
public static ByteBuffer getSubImage(ByteBuffer imageContent, int x, int y, int width, int height) throws Exception {
ByteArrayInputStream in = new ByteArrayInputStream(imageContent.array());
BufferedImage image = ImageIO.read(in);
BufferedImage subImage = image.getSubimage(x, y, width, height);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(subImage, "jpeg", out);
return ByteBuffer.wrap(out.toByteArray());
}