图片变形

需要依赖的包


compile 'jp.wasabeef:glide-transformations:3.0.1'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'


public class BecomeActivity extends AppCompatActivity implements View.OnClickListener {

    protected Button btn;
    protected ImageView iv;
    private String IMG_URL_0 = "http://zhanhui.3158.cn/data/attachment/exhibition/data/attachment/exhibition/article/2016/02/17/0d6437a313155f933c13971a0ba22cf4.jpg";
    private String IMG_URL_1 = "http://img2015.zdface.com/20171115/89eef31e783ccd13f2cdf12ab04298e3.jpg";
    private String IMG_URL_2 = "http://img003.21cnimg.com/photos/album/20161114/m600/6CDB31F812CC273DD89E4AA58594A217.jpeg";
    private String IMG_URL_3 = "http://p0.so.qhimgs1.com/t0195918c00ff0b8c1c.jpg";
    private String IMG_URL_4 = "http://himg2.huanqiu.com/attachment2010/2016/1026/15/06/20161026030615719.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_become);
        initView();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn) {
            showDialog();
        }
    }

    private void showDialog() {
        DialogUtil.showListDialog(this, "图片的形状的变换!", new String[]{
                "0,将图像剪切成圆",
                "1,将图像剪切成三角形",
                "2,将图像剪切成多角形",
                "3,将图像剪切成曲线形",
                "4,将图像剪切成圆角形",
        }, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0:
                        Glide.with(BecomeActivity.this)
                                .load(IMG_URL_0)
                                .apply(bitmapTransform(new CropCircleTransformation()))
                                .into(iv);
                        break;
                    case 1:
                        Glide.with(BecomeActivity.this)
                                .load(IMG_URL_1)
                                .apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.mipmap.mask_trangle))))
                                .into(iv);
                        break;
                    case 2:
                        Glide.with(BecomeActivity.this)
                                .load(IMG_URL_2)
                                .apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.mipmap.mask_starfish))))
                                .into(iv);
                        break;
                    case 3:
                        Glide.with(BecomeActivity.this)
                                .load(IMG_URL_3)
                                .apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_chat_right))))
                                .into(iv);
                        break;
                    case 4:
                        Glide.with(BecomeActivity.this)
                                .load(IMG_URL_4)
                                .apply(bitmapTransform(new RoundedCornersTransformation(45, 0,
                                        RoundedCornersTransformation.CornerType.ALL)))
                                .into(iv);
                        break;
                }
            }
      });
    }

    private void initView() {
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(BecomeActivity.this);
        iv = (ImageView) findViewById(R.id.iv);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值