How can I crop image to square using picasso library on Android?
I need following:
and I also need
How can I crop image to square using picasso library on Android?
I need following:
and I also need
The following project provides a lot of different transformations for Picasso
https://github.com/wasabeef/picasso-transformations
The one you are interested is named CropSquareTransformation
and you can apply it by using the following code
Picasso.with(mContext)
.load(R.drawable.demo)
.transform(transformation)
.transform(new CropSquareTransformation())
.into(holder.image);
You could add the dependency or copy and paste the classes you need.
Using a custom imageview:
public class SquareImageView extends android.support.v7.widget.AppCompatImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); //Snap to width
}
}
In your xml:
<com.my.package.SquareImageView
android:layout_width="match_parent"
android:layout_height="wrap_content">