5

I have tried to use imgscalr library with the following crop method:

Scalr.crop(image, height, width);

But it always crops starting at the left upper corner of the image. Can I tweak this behavior to start in the right bottom corner or center?

phouse512
  • 650
  • 4
  • 15
  • 27
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

5

Definitely - just use the other crop operation that takes x,y,width,height arguments.

Riyad Kalla
  • 10,604
  • 7
  • 53
  • 56
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);