图片加载得工具类

自己写的项目 对图片加载要求不高 所以在加载得时候用了 几个常见得加载工具
glide 
Picasso
image-loader
有点蛋疼 其实都没有什么太大得差别 只是完成异步加载就行了  
导入得 
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
imagerloder 得包下的是本地 想用得可以自己百度导入地址
用imagerloder 的在 
      
      
 
 每次都得先instance 有点麻烦
用Glide就方便多了 有小问题事不能加载bitmap图片 还得转成成btye【】
还有图像显示方向 在三星手机上拍照会自动旋转90度
所以我又加了方向调整 但是问题是这个0f 是指照片本来就是正常方向为0f
在三星上会把拍出来的照片左旋转90度作为0f 这个就尴尬了 这个方法就没用了 只能用过在加载得控件获取方向调整了 好麻烦
new RotateTransformation(getActivity() , 0f)
Glide. with(getActivity().getApplicationContext()).load( URL)//图片得加载地址 .transform( new RotateTransformation(getActivity() , 0f)) .error(R.mipmap. load_img_error) //加载错误时显示得图片 .into( userImgView) ;//图片加载得控件id
Glide还有加载图片时过度图片得设置方法 对异步加载图片来说完全够用了
有需求得可以研究下Glide得文档 随便写写 以后查找方便
//简单得查询图像方向 进行调整 0f不旋转 90f旋转90度
public class RotateTransformation extends BitmapTransformation {
    private float rotateRotationAngle = 0f;

    public RotateTransformation(Context context, float rotateRotationAngle) {
        super(context);
        this.rotateRotationAngle = rotateRotationAngle;
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        Matrix matrix = new Matrix();
        matrix.postRotate(rotateRotationAngle);
        return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
    }

    @Override
    public String getId() {
        return "rotate" + rotateRotationAngle;
    }
}

       
       
Picasso.with(BinderItemActivity.this).load(URL).into(imageView);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值