5

我尝试将 imgscalr 库与以下裁剪方法一起使用:

Scalr.crop(image, height, width);

但它总是从图像的左上角开始裁剪。我可以调整此行为以从右下角或中心开始吗?

4

2 回答 2

5

绝对 - 只需使用带有x,y,width,height参数的其他crop操作。

于 2014-12-09T01:51:37.543 回答
2
//center
Scalr.crop(image,
    (image.getWidth() - width) / 2, (image.getHeight() - height) / 2,
    width, height);

//top left:
Scalr.crop(image, width, height);

//top right:
Scalr.crop(image,
    image.getWidth() - width, 0,
    width, height);

//bottom left:
Scalr.crop(image,
    0, image.getHeight() - height,
    width, height);

//bottom right:
Scalr.crop(image,
    image.getWidth() - width, image.getHeight() - height,
    width, height);
于 2017-05-05T09:50:04.793 回答