@Override public void onNext() { storyStatusView.pause(); ++counter; target.setModel(statusResources[counter]); Glide.with(image.getContext()) .load(target.getModel()) .asBitmap() .crossFade() .centerCrop() .skipMemoryCache(!isCaching) .diskCacheStrategy(isCaching ? DiskCacheStrategy.ALL : DiskCacheStrategy.NONE) .transform(new CenterCrop(image.getContext()), new DelayBitmapTransformation(1000)) .listener(new LoggingListener<String, Bitmap>()) .into(target); }
@Override public void onPrev() { if (counter - 1 < 0) return; storyStatusView.pause(); --counter; target.setModel(statusResources[counter]); Glide.with(image.getContext()) .load(target.getModel()) .asBitmap() .centerCrop() .crossFade() .skipMemoryCache(!isCaching) .diskCacheStrategy(isCaching ? DiskCacheStrategy.ALL : DiskCacheStrategy.NONE) .transform(new CenterCrop(image.getContext()), new DelayBitmapTransformation(1000)) .listener(new LoggingListener<String, Bitmap>()) .into(target); }
@BindingAdapter(value = {"imageUrl", "defaultImg", "radius"}, requireAll = false) public static void setImage(ImageView imageView, String imageUrl, Drawable defaultImg, int radius) { DrawableRequestBuilder drawableTypeRequest = Glide.with(imageView.getContext()).load(imageUrl).crossFade(); if (defaultImg != null) { drawableTypeRequest.placeholder(defaultImg).error(defaultImg); } else { drawableTypeRequest.placeholder(R.drawable.bg_defautl_imageview).error(R.drawable.bg_defautl_imageview); } if (radius > 0) { drawableTypeRequest.bitmapTransform(new CenterCrop(imageView.getContext()), new RoundedCornersTransformation(imageView.getContext(), PixelUtil.dp2px(radius), 0)); } else { drawableTypeRequest.bitmapTransform(new CenterCrop(imageView.getContext())); } drawableTypeRequest.into(imageView); }
@SuppressWarnings("unchecked") private void setupGlideOptions() { options = new RequestOptions(); if (isShapeCircle) { if (Defaults.CIRCLE_RADIUS > 0) { options.transforms(new CenterCrop(), new RoundedCorners(Defaults.CIRCLE_RADIUS)); } else { options.circleCrop(); } } options.override(Defaults.IMAGE_HEIGHT, Defaults.IMAGE_HEIGHT); options.placeholder(placeholder_image); options.priority(Priority.HIGH); }
@SuppressWarnings("unchecked") private void setupGlideOptions() { options = new RequestOptions(); int size; if (isShapeCircle) { if (Defaults.CIRCLE_RADIUS > 0) { size = (int) (0.65 * Defaults.IMAGE_HEIGHT); options.transforms(new CenterCrop(), new RoundedCorners(Defaults.CIRCLE_RADIUS)); } else { size = Defaults.IMAGE_HEIGHT; options.circleCrop(); } } else { size = (int) (0.65 * Defaults.IMAGE_HEIGHT); } options.override(size, size); options.error(error_image); options.priority(Priority.HIGH); }
/** * 异步加载圆角图片, 使用 Glide 内置的圆角裁剪 —— bitmapTransform. * * 注意: bitmapTransform 与 外在的裁剪不兼容。即: https://github.com/wasabeef/glide-transformations/issues/54 * * 1. 此时的 imageView 不能是自定义的圆角View. * 2. scaleType 也不能设。 * * 否则重复裁剪, 会有 bug. * * @param url 图片路径 * @param drawableId 占位图 * @param radiusPixels 圆角像素值 */ public static void loadRoundImage(ImageView imageView, String url, int drawableId, int radiusPixels) { if(imageView == null) { Log.e(TAG, "loadRoundImage() -> imageView is null"); return; } Context context = imageView.getContext(); if(!isValid(context)) return ; Glide.with(context) .load(url) .placeholder(drawableId) .error(drawableId) .bitmapTransform( new CenterCrop(context), new RoundedCornersTransformation(context, radiusPixels, 0) ) .crossFade() .into(imageView); }
@Override protected void load(Context context) throws Exception { String url = "http://placehold.it/3000x2000/AAFF00/000000&text=IMAGE"; int[] requestedSize = new int[] {540, 540}; Glide .with(this) .load(url) .override(requestedSize[0], requestedSize[1]) .transform(new DelayBitmapTransformation(3000), new CenterCrop(context)) .skipMemoryCache(true) .diskCacheStrategy(NONE) .listener(new LoggingListener<String, GlideDrawable>()) .thumbnail(Glide .with(this) .load(url) .override(512, 384) .transform(new DelayBitmapTransformation(1000), new CenterCrop(context)) .skipMemoryCache(true) .diskCacheStrategy(NONE) .listener(new LoggingListener<String, GlideDrawable>()) ) .into(imageView) ; }
@Test @SuppressWarnings({"unchecked", "varargs"}) public void testApplyMultiTransform() { options.transforms(new CircleCrop(), new CenterCrop()); assertThat(options.isTransformationRequired()).isTrue(); assertThat(options.getTransformations()).containsKey(Bitmap.class); assertThat(options.getTransformations().get(Bitmap.class)) .isInstanceOf(MultiTransformation.class); }
public void loadWithRoundCorners(String image, int radius, int margin, ImageView previewImage) { Context context = weakContext.get(); if (context != null) { Glide.with(context) .load(image) .centerCrop() .bitmapTransform(new CenterCrop(context), new RoundedCornersTransform(context, radius, margin, RoundedCornersTransform.CornerType.LEFT)) .into(previewImage); } }
void bind(String url) { target.setModel(url); // update target's cache Glide .with(image.getContext()) .load(url) .asBitmap() .placeholder(R.drawable.github_232_progress) .centerCrop() // needs explicit transformation, because we're using a custom target .transform(new CenterCrop(image.getContext()), new DelayBitmapTransformation(1000)) .listener(new LoggingListener<String, Bitmap>()) .into(target) ; }
/** * Construct a standard ImageLoader object. */ public ImageLoader(Context context) { VariableWidthImageLoader imageLoader = new VariableWidthImageLoader(context); mGlideModelRequest = Glide.with(context).using(imageLoader); mCenterCrop = new CenterCrop(Glide.get(context).getBitmapPool()); mNone = Transformation.NONE; }
@Override public void onBindViewHolder(ViewHolder vh, int i) { Glide.with(mContext).load(mResponse.getResults().get(i).getUrl()).bitmapTransform( new CenterCrop(mPool), new RoundedCornersTransformation(mPool, 8, 0)) //.crossFade() .listener( GlidePalette.with(mResponse.getResults().get(i).getUrl()).intoCallBack(palette -> { if (mPaletteCallback != null) mPaletteCallback.onPaletteReady(i, palette); })).diskCacheStrategy(DiskCacheStrategy.ALL).into(vh.meiZi); }
public static void loadAvatarUrlWithRadius(String imgUrl, ImageView imageView) { loadAvatarUrlToReqBuilder(imgUrl, imageView) .bitmapTransform(new CenterCrop(imageView.getContext()), new RoundedCornersTransformation(imageView.getContext(), 8, 0)) .into(imageView); }
public static void loadAvatarUrlWithRadius(String imgUrl, ImageView imageView, @DrawableRes int drawableRes) { loadAvatarUrlToReqBuilder(imgUrl, imageView, drawableRes) .bitmapTransform(new CenterCrop(imageView.getContext()), new RoundedCornersTransformation(imageView.getContext(), 8, 0)) .into(imageView); }
public void initBackgroundImage(ImageView background) { Glide.with(context).load(R.drawable.main_background) .apply(new RequestOptions().transform(new CenterCrop())).into(background); }
private void setHeaderBackground() { ImageView headerImage = (ImageView) mNavigationView.getHeaderView(0).findViewById(R.id.nav_header_image); Glide.with(getApplicationContext()).load(R.drawable.main_background).apply(new RequestOptions().transform(new CenterCrop())).into(headerImage); }
private void setHeaderBackground() { ImageView headerImage = (ImageView) mNavigationView.getHeaderView(0).findViewById(R.id.nav_reader_header_image); Glide.with(getApplicationContext()).load(R.drawable.main_background).apply(new RequestOptions().transform(new CenterCrop())).into(headerImage); }
/** * Construct a standard ImageLoader object. */ public ImageLoader(Context context) { VariableWidthImageLoader imageLoader = new VariableWidthImageLoader(context); mGlideModelRequest = Glide.with(context).using(imageLoader).from(String.class).asBitmap(); mCenterCrop = new CenterCrop(Glide.get(context).getBitmapPool()); }
@Inject GlideImageLoader(Context context) { this.glideModelRequest = Glide.with(context).from(String.class).asBitmap(); this.centerCrop = new CenterCrop(Glide.get(context).getBitmapPool()); }
public DrawableRequestBuilder<ModelType> centerCrop() { return bitmapTransform(new CenterCrop(glide.getBitmapPool())); }
@Override public GenericRequestBuilder getPreloadRequestBuilder(Entry item) { return Glide.with(mContext).load(item.getUrl()).bitmapTransform(new CenterCrop(mPool), new RoundedCornersTransformation(mPool, 8, 0)) //.crossFade() .diskCacheStrategy(DiskCacheStrategy.ALL); }
/** * Construct a standard ImageLoader object. */ public ImageLoader(Context context) { requestManager = Glide.with(context); mCenterCrop = new CenterCrop(Glide.get(context).getBitmapPool()); mFitCenter = new FitCenter(Glide.get(context).getBitmapPool()); }
/** * 加载圆角图 * * @param context * @param imgUrl * @param placeholder * @param imageView * @param radiusDp */ public static void loadRound(Context context, String imgUrl, @DrawableRes int placeholder, ImageView imageView, int radiusDp) { Glide.with(context) .load(imgUrl) .placeholder(placeholder) .error(placeholder) .transform(new CenterCrop(context), new GlideRoundTransform(context, radiusDp)) .into(imageView); }
/** * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterCrop} to all default types, and * ignores unknown types. * * <p>This will override previous calls to {@link #dontTransform()}. * * @see #optionalTransform(Class, Transformation) * @see #centerCrop() */ public RequestOptions optionalCenterCrop() { return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); }
/** * Applies {@link CenterCrop} to all default types and * throws an exception if asked to transform an unknown type. * * <p>this will override previous calls to {@link #dontTransform()} ()}. * * @see #transform(Class, Transformation) * @see #optionalCenterCrop() */ public RequestOptions centerCrop() { return transform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); }
/** * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterCrop} to all default types, and * ignores unknown types. * * <p>This will override previous calls to {@link #dontTransform()}. * * @see #optionalTransform(Class, Transformation) * @see #centerCrop() */ @CheckResult public RequestOptions optionalCenterCrop() { return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); }
/** * Applies {@link CenterCrop} to all default types and * throws an exception if asked to transform an unknown type. * * <p>this will override previous calls to {@link #dontTransform()} ()}. * * @see #transform(Class, Transformation) * @see #optionalCenterCrop() */ @CheckResult public RequestOptions centerCrop() { return transform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); }
/** * Transform images using {@link CenterCrop}. * * @return This RequestBuilder */ public BitmapRequestBuilder<ModelType, TranscodeType> centerCrop() { return transform(new CenterCrop(bitmapPool)); }