Glide: Glide 4.1.1: how to set tint color for ImageView after successfully loading SVG

Created on 11 Sep 2017  Â·  3Comments  Â·  Source: bumptech/glide

I followed this sample: https://github.com/bumptech/glide/tree/master/samples/svg/src/main/java/com/bumptech/glide/samples/svg

After successfully loading SVG file with Glide 4.1.1, i want to set tint color for ImageView, but setColorFilter NOT WORKING

My source:

package com.example.quangson.glidesvg;

import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;

import android.content.ContentResolver;
import android.graphics.PorterDuff;
import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.bumptech.glide.RequestBuilder;
import com.example.quangson.glidesvg.glide.GlideApp;
import com.example.quangson.glidesvg.glide.SvgSoftwareLayerSetter;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "SVGActivity";
    private ImageView imageViewSVG;
    private ImageView imageViewPNG;
    private RequestBuilder<PictureDrawable> requestBuilder;

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

        imageViewSVG = (ImageView) findViewById(R.id.svg_image_view1);
        imageViewPNG = (ImageView) findViewById(R.id.svg_image_view2);

        imageViewPNG.setImageResource(R.drawable.image_mylogo);

        requestBuilder = GlideApp.with(this)
                .as(PictureDrawable.class)
                .error(R.drawable.image_error)
                .transition(withCrossFade())
                .listener(new SvgSoftwareLayerSetter());
        Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/"  + R.raw.android_toy_h);
        requestBuilder.load(uri).into(imageViewSVG);

        imageViewSVG.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_IN);
        imageViewPNG.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_IN);
    }
}

In my source:
I loaded PNG image (from res/drawable) into imageViewPNG and setColorFilter for imageViewPNG ⇒ WORKING
I loaded SVG image (from res/raw) into imageViewSVG and setColorFilter for imageViewSVG ⇒ NOT WORKING (Loaded SVG file successfully but can't setColorFilter)

I want to change SVG image color when i clicked button.

Please help me set tint color for imageViewSVG.
Thanks


I followed this issue (my issue): #1953 but it can not resolve my problem
I have been researching for a long time but still can't change color ImageView after successfully loading SVG
Can you help me a solution?

PictureDrawable support setColorFilter: https://developer.android.com/reference/android/graphics/drawable/PictureDrawable.html

Looking forward for your help.
Thanks

question stale

Most helpful comment

@sonzerolee For your information, I made a library for Glide and SVG that support setColorFilter 😉
https://github.com/qoqa/glide-svg

All 3 comments

SVG support isn't officially part of the library and I'm unfortunately not particularly familiar with SVG or PictureDrawable. It might help others if you clarify what you mean by "not working".

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@sonzerolee For your information, I made a library for Glide and SVG that support setColorFilter 😉
https://github.com/qoqa/glide-svg

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mttmllns picture mttmllns  Â·  3Comments

piedpiperlol picture piedpiperlol  Â·  3Comments

technoir42 picture technoir42  Â·  3Comments

Anton111111 picture Anton111111  Â·  3Comments

sant527 picture sant527  Â·  3Comments