How do I set the starting position of a crop using imgscalr?

I tried using imgscalr library with the following cropping method:

Scalr.crop(image, height, width);

      

But it always settles starting at the top left of the image. Can I customize this behavior to start at the bottom right or center?

+3


source to share


2 answers


Definitely - just use another operation crop

that takes x, y, width, height arguments .



+4


source


//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);

      



0


source







All Articles