自己写的项目 对图片加载要求不高 所以在加载得时候用了 几个常见得加载工具 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(HttpUrlUtil.URL_PRE + uHeadImage)//图片得加载地址 .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; } }
|