Resize image to full width and variable height with Picasso

前端 未结 12 1559
野趣味
野趣味 2020-11-29 17:10

I have a listView with an adapter that contains ImageView of variable size (width and height). I need resize the pictures load with Picasso to the max width of

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 17:42

    public class CropSquareTransformation implements Transformation {
    
      private int mWidth;
      private int mHeight;
    
      @Override public Bitmap transform(Bitmap source) {
        int size = Math.min(source.getWidth(), source.getHeight());
    
        mWidth = (source.getWidth() - size) / 2;
        mHeight = (source.getHeight() - size) / 2;
    
        Bitmap bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
        if (bitmap != source) {
          source.recycle();
        }
    
        return bitmap;
      }
    
      @Override public String key() {
        return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
      }
    

    More transformations: https://github.com/wasabeef/picasso-transformations

提交回复
热议问题