@Test public void testRoundedCorners_usePool() throws ExecutionException, InterruptedException { canonicalBitmap = canonicalBitmap.scale(0.1f); Bitmap redRect = createRect( Color.RED, canonicalBitmap.getWidth(), canonicalBitmap.getHeight(), Bitmap.Config.ARGB_8888); Glide.get(context).getBitmapPool().put(redRect); Bitmap roundedRect = bitmapRegressionTester.test( GlideApp.with(context) .asBitmap() .load(canonicalBitmap.getBitmap()) .override(canonicalBitmap.getWidth(), canonicalBitmap.getHeight()) .transform(new RoundedCorners(5))); assertThat(roundedRect).isEqualTo(redRect); }
@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); }
@Test public void load_withShapeDrawableResourceId_asDrawable_withTransformation_validSize_succeeds() throws ExecutionException, InterruptedException { Drawable drawable = Glide.with(context) .load(ResourceIds.drawable.shape_drawable) .apply(bitmapTransform(new RoundedCorners(10))) .submit(100, 200) .get(); assertThat(drawable).isNotNull(); assertThat(drawable.getIntrinsicWidth()).isEqualTo(100); assertThat(drawable.getIntrinsicHeight()).isEqualTo(200); }
@Test public void testRoundedCorners() throws ExecutionException, InterruptedException { bitmapRegressionTester.test( GlideApp.with(context) .asBitmap() .load(canonicalBitmap.getBitmap()) .transform(new RoundedCorners(5))); }
@Test public void testRoundedCorners_overRounded() throws ExecutionException, InterruptedException { bitmapRegressionTester.test( GlideApp.with(context) .asBitmap() .load(canonicalBitmap.getBitmap()) .transform(new RoundedCorners(20))); }
public GlideManager(Builder builder){ RequestOptions options = new RequestOptions() .placeholder(builder.placeresid); if (builder.eroorresid != 0){ options.error(builder.eroorresid); } switch (builder.type){ case BITMAP_SCAN_CENTERN: options.centerCrop(); break; case BITMAP_SCAN_FIT: options.fitCenter(); break; default: break; } if (builder.setCircleCrop){ options.circleCrop(); } if (builder.radius != 0){ options.transform(new RoundedCorners(builder.radius)); } RequestBuilder requestBuilder = null; requestBuilder = Glide.with(builder.context).load(builder.source); if (builder.animtime > 0){ requestBuilder.transition(new DrawableTransitionOptions().crossFade(builder.animtime)); } requestBuilder.apply(options) .listener(new LoadListener()) .into(builder.imageView); }
/** * 加载圆角图片 * * @param obj 加载的图片资源 * @param iv * @param dp 圆角尺寸-dp * @param placeholderResource -占位图 * @param isOfficial-是否官方模式圆角 */ public static void loadRoundImg(Object obj, ImageView iv, float dp, int placeholderResource, boolean isOfficial) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholderResource) .placeholder(placeholderResource) .fallback(placeholderResource) .dontAnimate() .transform(isOfficial ? new RoundedCorners(dp2px(dp)) : new GlideRoundTransform(iv.getContext(), dp2px(dp)))).into(iv); }
/** * 加载圆角图片 * * @param obj 加载的图片资源 * @param iv * @param dp 圆角尺寸-dp * @param placeholder -占位图 * @param isOfficial-是否官方模式圆角 */ public static void loadRoundImg(Object obj, ImageView iv, float dp, Drawable placeholder, boolean isOfficial) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholder) .placeholder(placeholder) .fallback(placeholder) .dontAnimate() .transform(isOfficial ? new RoundedCorners(dp2px(dp)) : new GlideRoundTransform(iv.getContext(), dp2px(dp)))).into(iv); }