Gif Images are not rounded
I have used below code to make GIF rounded RoundingParams roundingParams = imageView.getHierarchy().getRoundingParams(); roundingParams.setRoundAsCircle(true); imageView.getHierarchy().setRoundingParams(roundingParams); RoundingParams.asCircle().setRoundingMethod(RoundingMethod.OVERLAY_COLOR).setOverlayColor(getResources().getColor(R.color.white));
Still, it's not working. I have taken reference from these two links: https://github.com/facebook/fresco/issues/229 https://github.com/facebook/fresco/issues/188
Can you provide a sample url and a screenshot.
You are correctly trying to use OVERLAY_COLOR are your rounding method, but it doesn't look like your code ever assigns the params you create with that rounding method.
When you build your hierarchy in the first place you should set the RoundingParams that you are creating in the last line of your code snippet.
RoundingParams roundingParams = RoundingParams.asCircle().setRoundingMethod(RoundingMethod.OVERLAY_COLOR).setOverlayColor(getResources().getColor(R.color.white));
builder.setRoundingParams(roundingParams);
@IanChilds Thanks for your response. I have used below code in XML:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/profile_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="top"
fresco:placeholderImage="@drawable/blank_profile"
fresco:roundAsCircle="false"
fresco:roundWithOverlayColor="@android:color/transparent"
fresco:roundedCornerRadius="5dp"
fresco:roundingBorderColor="@color/grey"
fresco:roundingBorderWidth="1dp" />
in Java file,
profileImgView = (SimpleDraweeView) findViewById(R.id.profile_img);
RoundingParams roundingParams = RoundingParams.asCircle().setRoundingMethod(RoundingMethod.OVERLAY_COLOR).setOverlayColor(context.get().getResources().getColor(R.color.white));
roundingParams.setRoundAsCircle(true);
profileImgView.getHierarchy().setRoundingParams(roundingParams);
I get this exception: java.lang.IllegalStateException: Rounding method cannot be changed and it has to be set during construction time. at com.facebook.common.internal.Preconditions.checkState(Preconditions.java:173) at com.facebook.drawee.generic.GenericDraweeHierarchy.setRoundingParams(GenericDraweeHierarchy.java:637)
at line "profileImgView.getHierarchy().setRoundingParams(roundingParams);"
Your overlay color in the xml is transparent, so it gets ignored. Also, in your code you need to set the overlay color to the rounding params that you create. (Really, you shouldn't need the code at all if you set your xml up properly).
ok.. thanks Now I have used below code to set overlay color in xml.
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/profile_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="top"
fresco:placeholderImage="@drawable/blank_profile"
fresco:roundAsCircle="true"
fresco:roundWithOverlayColor="@color/white"
fresco:roundedCornerRadius="5dp"
fresco:roundingBorderColor="@color/grey"
fresco:roundingBorderWidth="1dp" />
In code, I am using doing this: profileImgView.setImageURI(Uri.parse(imageUrl));
Below is the URL which creating problem: http://giphy.com/gifs/supernatural-5OuelPHaXOHC0
while this image is getting downloaded properly: http://www.corporacionlimatambo.com/static/admin/img/loading.gif
Please see attached file:

What do you mean by "creating the problem"? What exactly is the problem now?
In your xml, you have both roundAsCircle=true and roundedCornerRadius=5dp. If you want it to be rounded as a circle, you need to remove the second of those.
Problem was that first image is not rounded here. I have to show images rounded/square conditionally. Either all the images will be rounded or square. Can't be both at the same time. Now It worked with below code. Thanks a lot for your response.
Because of that in layout I have used
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/profile_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="top"
fresco:placeholderImage="@drawable/blank_profile"
fresco:roundAsCircle="false"
fresco:roundWithOverlayColor="@color/white"
fresco:roundedCornerRadius="5dp"
fresco:roundingBorderColor="@color/grey"
fresco:roundingBorderWidth="1dp" />
in code, based on condition if(Utility.getShape() == CIRCULAR_SHAPE){ RoundingParams roundingParams = profileImgView.getHierarchy().getRoundingParams(); roundingParams.setRoundAsCircle(true); profileImgView.getHierarchy().setRoundingParams(roundingParams); } In else doing nothing. It will refer fresco attributes from xml.
No worries - glad it's working now!
@IanChilds Hello sir, I have one more query regarding this. I have used overlay color in xml to make gif images rounded. Problem is that when list item has selector, and we select any item image background is shown as overlay color because of that I used transparent color as overlay. But gif image requires some overlay color other than transparent.
Please see attached snapshots with overlay color is "some color(not transparent)".
default state

selected state

I am not able to set overlay color in code. It gives class cast exception for "RootFadeDrawable" and "RoundedCornersDrawable" I was thinking a way where in xml I can set overlay color "as transparent" and in code if Image is gif then only change overlay color so that all other images will look good.
I have tried below approach: in xml, <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/profile_img" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="top" fresco:placeholderImage="@drawable/blank" fresco:roundAsCircle="false" fresco:roundedCornerRadius="5dp"/>
in code,
GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); builder.setPressedStateOverlay(context.get().getResources().getDrawable(R.color.transparent)); builder.setOverlay(context.get().getResources().getDrawable(R.color.transparent)); RoundingParams roundingParams = profileImgView.getHierarchy().getRoundingParams(); if(roundingParams != null){ if(photoshape == Constants.CIRCULAR_SHAPE){ roundingParams.setRoundAsCircle(true); } else { roundingParams.setRoundAsCircle(false); } } builder.setRoundingParams(roundingParams); builder.setPlaceholderImage(R.drawable.blank); if(imageUrl.contains(".gif")) { builder.setPressedStateOverlay(context.get().getResources().getDrawable(R.color.grey)); builder.setOverlay(context.get().getResources().getDrawable(R.color.grey)); } imageview.setHierarchy(builder.build()); imageview.setImageURI(Uri.parse(imageUrl));
But with this, it overlaps image with overlay color :(
that class cast exception is a bug - the fix will be in the next version, and then you will be able to change to any rounding params you want dynamically, which will give you what you want.
thanks a lot... waiting for next release :+1:
Is this problem fixed?
Should be fixed, yes.
This problem still remaining in the latest version! @plamenko
GIF images could be round when I set app:roundWithOverlayColor attribute but the selector problem occurs.
I am using SimpleDraweeView to render gif image and I want rounded corner for that. My xml is <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/gif_priview_img" android:layout_width="@dimen/chat_image_max_width" android:layout_centerInParent="true" fresco:actualImageScaleType="fitXY" android:visibility="visible" fresco:roundedCornerRadius="15dp" fresco:roundingBorderColor="@color/grey" fresco:roundingBorderWidth="0dp" android:layout_height="@dimen/chat_image_max_width" fresco:roundWithOverlayColor="@color/white" fresco:roundAsCircle="false" />
My Java code DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Utility.decodeTags(mMessage.toString())) .setAutoPlayAnimations(true) .build(); SimpleDraweeView gifView = (SimpleDraweeView) attachMentViewLayout.findViewById(R.id.gif_priview_img); gifView.setController(controller);
This code is actually showing my gif image rounded but it shows white corner at end of image. May be this is because of below line in xml . fresco:roundWithOverlayColor="@color/white" But if i remove it, it is not showing rounded corner. It would be great if anyone can help me.
Hello,I have used below code by Kotlin to make GIF rounded,but it's not working for me
gifImage = SimpleDraweeView(context) gifImage?.id = R.id.outgoing_image_row_image_gif val gifImageParam: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(wrapContent, wrapContent) gifImage?.layoutParams = gifImageParam gifImage?.visibility = View.GONE val roundingParams = RoundingParams.asCircle().setRoundingMethod(RoundingMethod.OVERLAY_COLOR).setOverlayColor(ContextCompat.getColor(context, R.color.color_white)) gifImage?.hierarchy?.roundingParams = roundingParams