Comment puis-je recadrer l'image en carré en utilisant la bibliothèque picasso sur Android?Recadrer l'image en carré avec picasso
J'ai besoin suivant: cat one et cat two
Comment puis-je recadrer l'image en carré en utilisant la bibliothèque picasso sur Android?Recadrer l'image en carré avec picasso
J'ai besoin suivant: cat one et cat two
Le projet suivant fournit beaucoup de transformations différentes pour Picasso
https://github.com/wasabeef/picasso-transformations
Celui qui vous intéresse est nommé CropSquareTransformation
et vous pouvez l'appliquer par en utilisant le code suivant
Picasso.with(mContext)
.load(R.drawable.demo)
.transform(transformation)
.transform(new CropSquareTransformation())
.into(holder.image);
Vous pouvez ajouter la dépendance ou copier et coller les classes dont vous avez besoin.
Merci! C'est exactement ce dont j'avais besoin! –
L'utilisation d'un imageview personnalisé:
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
}
}
Dans votre xml:
<com.my.package.SquareImageView
android:layout_width="match_parent"
android:layout_height="wrap_content">
Cette question a été répondue ici, il peut peut-être aider à: http://stackoverflow.com/questions/30134438/ picasso-crop-to-a-view – rontho