/** * 显示图片 * @param context 上下文 * @param imageView 图片view * @param uri 图片路径 * @param bitmapTransformation bitmap转换器 */ private static void display(Context context, final ImageView imageView, String uri, BitmapTransformation bitmapTransformation, boolean isAvatar){ DrawableTypeRequest<String> drawableTypeRequest = Glide.with(context).load(uri); drawableTypeRequest .centerCrop() .placeholder(ERROR_IMAGE) .error(isAvatar ? AVATAR_IMAGE : ERROR_IMAGE) .diskCacheStrategy(DiskCacheStrategy.ALL) .dontAnimate(); // 添加转换器 if(null != bitmapTransformation){ drawableTypeRequest.bitmapTransform(bitmapTransformation); } // 设置图片 drawableTypeRequest.into(imageView); }
private void loadImage(ImageView iv, int resid) { Glide .with(this) // .load(url) .load(resid) // .fitCenter() //缩放在view中,图的中心点与view的中心点匹配 全图可见 .centerCrop() //缩放,一边贴view的边,就停止 .placeholder(R.mipmap.ic_launcher) //占位图 // .error(resid) //错误图 .crossFade() //淡入 .override(1000, 800) //图片尺寸 .transform(new BitmapTransformation(this) { @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { Bitmap bitmap = Bitmap.createBitmap(toTransform, 0, 300, outWidth, outHeight-300); return bitmap; } @Override public String getId() { return "aa"; } }) .diskCacheStrategy(DiskCacheStrategy.RESULT) //ALL=SOURCE+RESULT SOURCE原图尺寸 RESULT所以转化后的尺寸 NONE不缓存 .into(iv); }
public void handleUserAvatar(ImageView avatarIV, String url) { if (mDefaultAvatar == null) { Bitmap defaultAvatar = BitmapFactory.decodeResource(getResources(), R.drawable.default_avatar); mDefaultAvatar = new BitmapDrawable(getResources(), ImageUtil.toRoundCorner(defaultAvatar, 2)); } avatarIV.setImageTintList(null); GlideApp.with(this) .load(url) .placeholder(mDefaultAvatar) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .transforms(new BitmapTransformation() { @Override protected Bitmap transform(@NonNull BitmapPool bitmapPool, @NonNull Bitmap bitmap, int i, int i1) { Bitmap roundBitmap = ImageUtil.toRoundCorner(bitmap, 2); bitmapPool.put(roundBitmap); return roundBitmap; } @Override public void updateDiskCacheKey(MessageDigest messageDigest) { } }) .into(avatarIV); }
@Override public void setProfileImage(String url){ Glide.with(this) .load(url) .asBitmap() .centerCrop() .placeholder(R.drawable.profile_placeholder) .transform(new BitmapTransformation(this) { @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { return getCircleBitmap(toTransform); } @Override public String getId() { return "circle"; } }) .into(mHeaderProfileImage); }
public static void into(Activity activity, Object resPath, ImageView iv, BitmapTransformation bt) { if (!AppUtil.isSafe(activity)) { return; } if (resPath == null) { return; } if (bt == null) { Glide.with(activity).load(resPath).into(iv); } else { Glide.with(activity).load(resPath).transform(bt).into(iv); } }
@Override public void load(ImageView imageView, Object imageUrl, Object transformation) { Glide.with(mContext) .load(imageUrl) .crossFade() .transform((BitmapTransformation) transformation) .into(imageView); }
public static void displayImage(Context context, ImageView imageView, String url, int placeHolder, BitmapTransformation transformation){ test(url); Glide .with(context) .load(url) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .transform(transformation) .placeholder(placeHolder) .dontAnimate() .into(imageView); }
public static void displayImage(Context context, ImageView imageView, Uri uri, BitmapTransformation transformation){ KLog.d(uri); Glide .with(context) .load(uri) .transform(transformation) .into(imageView); }
public static void displayImage(Fragment fragment, ImageView imageView, String url, int placeholder, BitmapTransformation transformation){ test(url); Glide .with(fragment) .fromUri() .load(Uri.parse(url)) .transform(transformation) .placeholder(placeholder) .dontAnimate() .into(imageView); }
public static void loadResourceImage(Context context, ImageView view, int resId, @Nullable BitmapTransformation transformation) { DrawableRequestBuilder<Integer> request = Glide .with(context) .load(resId) .dontAnimate() .diskCacheStrategy(DiskCacheStrategy.SOURCE); if (transformation != null) { request.transform(transformation); } request.into(view); }
@Override public void loadImage(String url, final ImageView imageView) { Glide.with(imageView.getContext()).load(url).transform(new BitmapTransformation(imageView.getContext()) { @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { BlurTransformation blurTransformation = new BlurTransformation(imageView.getContext()); Resource<Bitmap> blurredBitmapResource = blurTransformation.transform(BitmapResource.obtain(toTransform, pool), 10, 1); Bitmap combinedBitmap; Bitmap bottom = blurredBitmapResource.get(); if ((combinedBitmap = pool.get(toTransform.getWidth(), bottom.getHeight() / 3 + toTransform.getHeight(), Bitmap.Config.ARGB_8888)) == null) { combinedBitmap = Bitmap.createBitmap(toTransform.getWidth(), bottom.getHeight() / 3 + toTransform.getHeight(), toTransform.getConfig()); } Canvas comboImage = new Canvas(combinedBitmap); comboImage.drawBitmap(toTransform, 0f, 0f, null); Matrix matrix = new Matrix(); matrix.postRotate(180); matrix.preScale(-1 , 1); matrix.postTranslate(0, toTransform.getHeight() * 2); comboImage.setMatrix(matrix); comboImage.drawBitmap(bottom, 0f, 0f, null); return BitmapResource.obtain(combinedBitmap, pool).get(); } @Override public String getId() { return ImageLoader.class.getName() + ".Transformation"; } }).into(imageView); }
public BitmapTransformation getTransformation() { return transformation; }
public BitmapTransformation[] getTransformation() { return transformation; }
/** * glide用它来改变图形的形状 */ public BitmapTransformation getTransformation() { return transformation; }
public static void loadRoundRect( Context context, String url, BitmapTransformation transformation, ImageView view) { Glide.with(context).load(url) .into(view); }
public static void loadImageRotated(Context context, ImageView view, String url, int placeHolder, BitmapTransformation... transformations) { Glide.with(context) .load(url) .transform(transformations).placeholder(placeHolder) .into(view); }
public static void loadImageRotated(Context context, ImageView view, String url, BitmapTransformation... transformations) { Glide.with(context) .load(url) .transform(transformations) .into(view); }
public static void load(Context context, ImageView view, String url, BitmapTransformation transformation, int placeHolder) { getDrawableTypeRequest(context, url).placeholder(placeHolder) .transform(transformation) .crossFade() .into(view); }
public static void loadImage(@NotNull Context mContext, @NotNull int resource, @NotNull ImageView view, BitmapTransformation transformation) { Glide.with(mContext).load(resource).transform(transformation).into(view); }
public GlideBitmapLoader(@NonNull RequestManager requestManager, @NonNull BitmapTransformation transformation) { this.requestManager = requestManager; this.transformation = transformation; }
public static BitmapTransformation createUsing(int viewportWidth, int viewportHeight) { return new GlideFillViewportTransformation(viewportWidth, viewportHeight); }