Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is possible to make transformation to placeholder as well? #317

Closed
korkag opened this issue Jan 27, 2015 · 7 comments
Closed

Is possible to make transformation to placeholder as well? #317

korkag opened this issue Jan 27, 2015 · 7 comments

Comments

@korkag
Copy link

korkag commented Jan 27, 2015

Let say i want to download image then to run circle transformation on it. Now i want to use placeholder as well. When placeholder image is displayed it has square canvas instead circle. Is it possible to run the transform (circle transform) to both placeholder and downloaded image?

Thanks

@floating-cat
Copy link
Contributor

A similar question before: #262

@korkag
Copy link
Author

korkag commented Jan 28, 2015

Currently i extend from ImageView and overriding onDraw method, something like:

boolean isRoundedCorner
protected void onDraw(Canvas canvas) {

        if (isRoundedCorner) {
            float radius = 90.0f; // angle of round corners
            Path clipPath = new Path();
            RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
            clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
            canvas.clipPath(clipPath);
        }

        super.onDraw(canvas);
}

@sjudd
Copy link
Collaborator

sjudd commented Jan 28, 2015

It's unfortunately not possible to apply Transformations to placeholders. The only way to do this would be to require every Transformation implementation to apply both to the original type (Bitmap, GifData) and the placeholder type (Drawable), which would be inconvenient for many Transformations and not possible for others.

The most efficient way to do this would be to make your placeholder rounded (ie modify the image in resources). I understand that's not always possible though.

@floating-cat
Copy link
Contributor

I recommend to use https://github.com/vinc3m1/RoundedImageView (which is better than circle transform) or other similar (like CircleImageView) instead of circle transform. Or as sjudd suggested to make your placeholder rounded.

edit: I found these two library I recommended can't perform animated Gifs. But BezelImageView (which also need to add style to attr.xml) works well for me.

@sjudd sjudd added the question label Jan 28, 2015
@FrancoisBlavoet
Copy link
Contributor

I ran into a similar issue.
I am using the support lib v4 RoundedBitmapDrawable in order to implement a RoundedImageView. This way I cover both rounded rectangles and circles.
In instances where I can't just use a rounded placeholder, I just create a RoundedBitmapDrawable from this resource and feed it to Glide as with .placeholder(drawable).
The only limitation is that BitmapShaders don't mesh well with LayerDrawable or ValueAnimator, so it is not possible to animate the transition from placeholder to final image.

@sjudd
Copy link
Collaborator

sjudd commented Apr 26, 2015

Thanks for the input guys. I'm going to close this, I don't think we're ever going to get to the point where we can consistently transform placeholders. A custom placeholder resource, or a special view may be the best way to go.

@TWiStErRob
Copy link
Collaborator

Potential workarounds in #1077.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants