Glide: GlideImage get not tinted

Created on 5 Dec 2016  路  3Comments  路  Source: bumptech/glide


Glide Version:
3.7.0
compile 'com.github.bumptech.glide:glide:3.7.0'


Integration libraries:
No other libs used. I've build a new project in AS 2.2.2 from scratch.
But using compile 'com.android.support:appcompat-v7:25.0.1' (but i guess it is not related :))


Device/Android Version:
It happens everywhere :)


Issue details / Repro steps / Use case background:
GlideImage get not tinted. Unless I load it asBitmap().
Maybe this is realted?! -> https://github.com/bumptech/glide/issues/1142

Probably I need much to say :D The code said everything.
However.
I've a project which loads some images with Glide. After the loading I tint the image via DrawableCompat. Unfortunately the image which will NOT loaded via asBitmap() will not be tinted!


Glide load line / GlideModule (if any) / list Adapter code (if any):

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ImageView notWorking = (ImageView) findViewById(R.id.not_working);
        final ImageView working = (ImageView) findViewById(R.id.working);

        Glide.with(this).load("http://i.imgur.com/BceY5EW.png").into(notWorking);
        Glide.with(this).load("http://i.imgur.com/BceY5EW.png").asBitmap().into(working);

        // Wait until it is loaded
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                tintImage(notWorking);
                tintImage(working);
            }
        }, 5000);
    }

    private void tintImage(final ImageView imageView) {
        final Drawable drawable = imageView.getDrawable();
        final Drawable wrappedDrawable = DrawableCompat.wrap(drawable).mutate();
        imageView.setImageDrawable(wrappedDrawable);
        DrawableCompat.setTint(wrappedDrawable, Color.RED);
    }


Layout XML:

    <ImageView
        android:id="@+id/not_working"
        android:layout_width="200dp"
        android:layout_height="200dp" />

    <ImageView
        android:id="@+id/working"
        android:layout_width="200dp"
        android:layout_height="200dp" />


Stack trace / LogCat:

Haven't one :)


Gif:
asasas

question

All 3 comments

I had same issue, switched loading asBitmap()

You need to tap into Glide-s mechanism to be able to tint properly. Between Glide....into() and Glide.clear() Glide assumes full control over the ImageView, getDrawable/setImageDrawable is not a good idea. See https://github.com/TWiStErRob/glide-support/tree/master/src/glide3/java/com/bumptech/glide/supportapp/github/_1142_tint_everything how to do it "the Glide way", your case will be TestFragmentWithTarget.

Note: "Wait until it is loaded" is exactly what .listener() and custom targets are for.

Let me know if you need more help than the above code examples.

I'm not sure why it's not working though, you could debug into the compat library to see if wrapping works correctly. Maybe GlideDrawables miss a feature that's required to support wrapping.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PatrickMA picture PatrickMA  路  3Comments

ersen-osman picture ersen-osman  路  3Comments

billy2271 picture billy2271  路  3Comments

Anton111111 picture Anton111111  路  3Comments

sergeyfitis picture sergeyfitis  路  3Comments