【发布时间】:2017-04-07 15:21:39
【问题描述】:
如何在 Android 上使用 picasso 库将图像裁剪为正方形?
我需要以下内容:
我还需要
【问题讨论】:
-
这里已经回答了这个问题,也许它可以帮助:stackoverflow.com/questions/30134438/picasso-crop-to-a-view
标签: android image picasso android-image
如何在 Android 上使用 picasso 库将图像裁剪为正方形?
我需要以下内容:
我还需要
【问题讨论】:
标签: android image picasso android-image
以下项目为毕加索提供了很多不同的变换
https://github.com/wasabeef/picasso-transformations
你感兴趣的是CropSquareTransformation,你可以使用下面的代码来申请
Picasso.with(mContext)
.load(R.drawable.demo)
.transform(transformation)
.transform(new CropSquareTransformation())
.into(holder.image);
你可以添加依赖或者复制粘贴你需要的类。
【讨论】:
使用自定义图像视图:
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
}
}
在你的 xml 中:
<com.my.package.SquareImageView
android:layout_width="match_parent"
android:layout_height="wrap_content">
【讨论】: