Picasso: .centerCrop() with Gravity parameter

Created on 23 Nov 2016  路  3Comments  路  Source: square/picasso

Is there any way in current version to crop image like centerCrop is doing, but to choose where image will be cropped? Something like .centerCrop(Gravity.TOP) or .centerCrop(Gravity.BOTTOM) etc. At this moment Gravity is CENTER.

Most helpful comment

47878b470 was merged a couple years ago, and doesn't seem to be in any tag. Would love a release at some point. ;-)

All 3 comments

This is already on master and will be in the next release.

47878b470 was merged a couple years ago, and doesn't seem to be in any tag. Would love a release at some point. ;-)

Sounds like the ball started rolling towards a 3.0 release, so we'll just have to be patient.

In the meantime, you can do some light cropping with something like this:

  private static class TopHalfTransformation implements Transformation {
    @Override public Bitmap transform(Bitmap source) {
      try {
        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight() / 2);
      } finally {
        source.recycle();
      }
    }

    @Override public String key() {
      return "half height";
    }
  }
Was this page helpful?
0 / 5 - 0 ratings