【问题标题】:Crop image as square with picasso用毕加索将图像裁剪为正方形
【发布时间】:2017-04-07 15:21:39
【问题描述】:

如何在 Android 上使用 picasso 库将图像裁剪为正方形?

我需要以下内容:

我还需要

【问题讨论】:

标签: android image picasso android-image


【解决方案1】:

以下项目为毕加索提供了很多不同的变换

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

你感兴趣的是CropSquareTransformation,你可以使用下面的代码来申请

Picasso.with(mContext)
       .load(R.drawable.demo)
       .transform(transformation)
       .transform(new CropSquareTransformation())
       .into(holder.image);

你可以添加依赖或者复制粘贴你需要的类。

【讨论】:

  • 谢谢!这正是我所需要的!
【解决方案2】:

使用自定义图像视图:

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">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-30
    • 2020-06-27
    • 2012-04-23
    • 2020-02-06
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多