corouteam / GlideToVectorYou

Load SVGs in Android with Glide
Apache License 2.0
208 stars 20 forks source link

setColorFilter not work #10

Open trongtrong opened 4 years ago

trongtrong commented 4 years ago

i am load image and set color filter but not work, can you help me ? GlideToVectorYou .init() .with(context) .withListener(new GlideToVectorYouListener() { @Override public void onLoadFailed() { } @Override public void onResourceReady() { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { holder.imgCategory.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ContextCompat.getColor(context, R.color.colorWhite), BlendModeCompat.SRC_ATOP)); } else { holder.imgCategory.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(context, R.color.colorWhite), PorterDuff.Mode.SRC_IN)); } } }) .load(Uri.parse(category.getAvatar()), holder.imgCategory);

PRobi23 commented 4 years ago

Hello, I also have this type of error also. I try this in two way:

    GlideToVectorYou
        .init()
        .with(view.context)
        .withListener(object : GlideToVectorYouListener {
            override fun onLoadFailed() {}
            override fun onResourceReady() {
                view.setColorFilter(ContextCompat.getColor(view.context, colorId))
            }
        })
        .load(imageUri, view)

I also tried to set simply the: view.setColorFilter(ContextCompat.getColor(view.context, colorId))

PRobi23 commented 4 years ago

This worked:

GlideToVectorYou .init() .with(view.context) .withListener(object : GlideToVectorYouListener { override fun onLoadFailed() {}

            override fun onResourceReady() {
                val paint = Paint()
                paint.colorFilter =
                    PorterDuffColorFilter(ContextCompat.getColor(view.context, colorId), PorterDuff.Mode.SRC_ATOP)
                view.setLayerPaint(paint)
            }
        })
        .load(imageUri, view)
forfiter91 commented 4 years ago

It is possible to add something like tintList to an image with this lib?

forfiter91 commented 4 years ago

For PNG i am doing it as below: Glide.with(getContext()) .asBitmap() .load(url) .listener(listener) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { Drawable drawable = new BitmapDrawable(getResources(), resource); Drawable wrappedDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(wrappedDrawable, mItemColorState); imageButton.setImageDrawable(wrappedDrawable); } }), getContext(), logoUrl);

YKuvonchbek commented 4 years ago

This worked:

GlideToVectorYou .init() .with(view.context) .withListener(object : GlideToVectorYouListener { override fun onLoadFailed() {}

            override fun onResourceReady() {
                val paint = Paint()
                paint.colorFilter =
                    PorterDuffColorFilter(ContextCompat.getColor(view.context, colorId), PorterDuff.Mode.SRC_ATOP)
                view.setLayerPaint(paint)
            }
        })
        .load(imageUri, view)

It does not work properly. When you set tint color all of the shape colored as solid. Edit: It works for some type of SVG files, but not all of them.