fresco icon indicating copy to clipboard operation
fresco copied to clipboard

RoundedCorner + fitCenter deforms final image

Open Armaxis opened this issue 11 years ago • 5 comments

I have stumbled upon an issue while using rounded corners with images, that doesn't take whole space. In my layout I have:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/cell_thumb"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            fresco:actualImageScaleType="fitCenter"
            fresco:placeholderImage="@drawable/logo"
            fresco:roundedCornerRadius="3dp"
            fresco:roundBottomLeft="false"
            fresco:roundBottomRight="false" />

When image has exact same aspect ratio as container - top corners get rounded perfectly and the result looks like this: Correct corners

But when image doesn't take full space and gets fitted inside (because I'm using fitCenter), instead of seeing layout background color I see image getting "expanded" with extra rows of pixels to take the remaining place, and then rounded corners getting applied.

Weird behavior

Is that a correct behavior of image processing? I wish it could just ignore rounded corners if image doesn't take the full space. In that case I will just additionally set up rounded corners on my layout, so when image is not taking whole space - layout will draw rounded corners.

Armaxis avatar Apr 16 '15 05:04 Armaxis

Yes, this is a known limitation. It is an Android bug when using BitmapShader. I'm afraid there is not much we can do. You can try using the other rounding mode by specifying the overlay color.

plamenko avatar Apr 16 '15 11:04 plamenko

Oh, I see. Well, I can probably just switch to centerCrop then, or get rid of those roundedCorners. By the way, do they affect the performance and page draw time significantly or not?

Also, maybe it is still possible to subscribe for event onFinalImageSet(), check the actual image size, and then disable corners? Or this will not work?

Armaxis avatar Apr 16 '15 15:04 Armaxis

@Armaxis, I wouldn't use controller listener for that. See whether a different rounding mode (OVERLAY_COLOR) would work for you: http://frescolib.org/docs/rounded-corners-and-circles.html#_ If not, then try using some scale type that ensures that the whole view is filled, like center-crop. Performance shouldn't be affected dramatically, and OVERLAY_COLOR is even more performant than the default mode, but the limitation is that it only looks good if the background is of the same color.

plamenko avatar Apr 16 '15 17:04 plamenko

@plamenko I considered (OVERLAY_COLOR), but that's not an option, because we use non-solid color background. But I've talked to designers and it turned out, that they don't want to have rounded corners anymore. So problem solved :) Maybe this issue should be highlighted in documentation for roundedCorners? It will save a lot of time for developers who might stumble upon same issue.

Armaxis avatar Apr 16 '15 18:04 Armaxis

Sure, I'll update the docs.

plamenko avatar Apr 16 '15 23:04 plamenko