Glide Version: 3.7.0
Integration libraries: no
Device/Android Version: GT-I9500 5.0.1
Issue details / Repro steps / Use case background:
Glide load line / GlideModule (if any) / list Adapter code (if any):
in class which is extends from ImageView
Glide.with(getContext())
.load(pathToImage)
.bitmapTransform(new RoundedCornersTransformation(getContext(), 100, 0))
.placeholder(R.color.orange_red)
.error(defaultPhotoId)
.dontAnimate()
.listener(this)
.into(this);
Layout XML:
<com.application.ImageGlide
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I user only square image
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int width = MeasureSpec.getSize(widthMeasureSpec);
if (width > 0) {
setMeasuredDimension(width, width);
}
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
1.png - start screen
2.png - scroll bottom and return top


load(null): https://github.com/bumptech/glide/issues/268 so you just need to do .error(R.drawable.x).fallback(R.drawable.x) if you want to treat null as error.Btw, why did you close the issue? Accident or found a solution?
@TWiStErRob error resource would be use if for 'onException' callback return false.
But now I can see what error resource is use transform before display.
As placeholder I use shape (it's not problem). But if I use non solid drawable (vector for example) - it is'not use transformation. And this is really bad, because need preparatory work for placeholder.
Yes, you need to do some work on the placeholder, because there's no general way to do transforms.
You have two options:
java
private BitmapDrawable transformDrawable(Drawable drawable, Transformation<Bitmap> transform, int size) {
Bitmap bitmap = Bitmap.createBitmap(size, size, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, size, size);
drawable.draw(canvas);
Resource<Bitmap> original = BitmapResource.obtain(bitmap, Glide.get(getContext()).getBitmapPool());
Resource<Bitmap> rounded = transform.transform(original, size, size);
if (!original.equals(rounded)) {
original.recycle();
}
return new BitmapDrawable(getResources(), rounded.get());
}
Ty
it's not work for MultiTransformation?
I'm using CenterCrop and RoundedCorners to load image. and use the transformDrawable() methd to load placeholder.but it's not working. this is my code:
MultiTransformation transformation = new MultiTransformation(new CenterCrop(), new RoundedCorners(roundingRadius));
BitmapDrawable bitmapDrawable = transformDrawable(context, placeholder,
transformation);
GlideApp.with(context)
.load(url)
.placeholder(bitmapDrawable)
.error(bitmapDrawable)
.transform(transformation)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
@TWiStErRob when you say "Once!" does it mean we have to keep global reference for that BitmapDrawable, say when we load the app and later we can use same reference everywhere throughout the app? Please correct me if I am wrong. Thanks.
Most helpful comment
Yes, you need to do some work on the placeholder, because there's no general way to do transforms.
You have two options:
For full example see https://github.com/TWiStErRob/glide-support/commit/1b4d9d3d1abca672714d5ce192c678d181adab80
java private BitmapDrawable transformDrawable(Drawable drawable, Transformation<Bitmap> transform, int size) { Bitmap bitmap = Bitmap.createBitmap(size, size, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, size, size); drawable.draw(canvas); Resource<Bitmap> original = BitmapResource.obtain(bitmap, Glide.get(getContext()).getBitmapPool()); Resource<Bitmap> rounded = transform.transform(original, size, size); if (!original.equals(rounded)) { original.recycle(); } return new BitmapDrawable(getResources(), rounded.get()); }