我尝试将 imgscalr 库与以下裁剪方法一起使用:
Scalr.crop(image, height, width);
但它总是从图像的左上角开始裁剪。我可以调整此行为以从右下角或中心开始吗?
我尝试将 imgscalr 库与以下裁剪方法一起使用:
Scalr.crop(image, height, width);
但它总是从图像的左上角开始裁剪。我可以调整此行为以从右下角或中心开始吗?
绝对 - 只需使用带有x,y,width,height参数的其他crop
操作。
//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);