Fresco: Scaling up image with RoundingParams works wrong (Android 9.0)

Created on 26 Feb 2019  路  5Comments  路  Source: facebook/fresco

Description

Hello, I've found a problem with scaling up images with Fresco with rounding params in Android 9.0.

When image is small and it need to be scaled up to fill View (with CENTER_CROP ScaleType for example) it displays with artifacts. Looks like pixels are not interpolated to fill the view, but scaled separately and image looks pixelated

At the screenshot: top picture looks as expected, and the bottom one (with rounding) pixelated
screenshot_20190226-150018_my application

Reproduction

run code on Android 9 device (reprodused on Samsung Galaxy S 9 and Pixel 2)

public class MainActivity extends AppCompatActivity {

    private static final String SMALL_IMAGE_URL = "https://www.dropbox.com/s/5mxb5a2mae773c9/small.jpg?dl=1";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Fresco.initialize(this);

        LinearLayout root = new LinearLayout(this);

        root.setOrientation(LinearLayout.VERTICAL);
        root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        //first view without rounding
        SimpleDraweeView firstImage = new SimpleDraweeView(this);
        firstImage.setImageURI(SMALL_IMAGE_URL);
        firstImage.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
        root.addView(firstImage, paramsForImage());

        //same view, but with rounding
        SimpleDraweeView secondImage = new SimpleDraweeView(this);
        secondImage.setImageURI(SMALL_IMAGE_URL);
        secondImage.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
        secondImage.getHierarchy().setRoundingParams(RoundingParams.fromCornersRadius(24));
        root.addView(secondImage, paramsForImage());

        setContentView(root);
    }

    private LinearLayout.LayoutParams paramsForImage() {
        LinearLayout.LayoutParams result = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        result.weight = 1;
        return result;
    }

}

Additional Information

May be BitmapShader, which is used for rounding, works unexpected at Android 9.0
Rounding with overlay color works fine

  • Fresco version: 1.12.1
  • Platform version: Android 9.0
bug good first issue help wanted starter-task

Most helpful comment

This should be fixed with 6d3a538525d2eab10bd59400ee1fcaf9569bdf79. Thanks @otopba!

All 5 comments

cc: @oprisnik

That's odd... Definitely looks like a bug. Thanks for reporting!

This is likely caused by the bitmap shader used to draw rounded bitmaps, which likely doesn't properly upscale:

https://github.com/facebook/fresco/blob/bc048e43bce562413c96c3ba2a360e9f9f0f3ca1/drawee/src/main/java/com/facebook/drawee/drawable/RoundedBitmapDrawable.java#L76

Do you need this for fully circular images or just for rounded corners @dmitrychistyakov ? As a workaround, if it's fully circular, you can use a BitmapTransformation that uses the native rounding filter instead, which is much more performant.

@oprisnik I use both rounding corners and circle rounding. Thank you for BitmapTransformation hint, I'll try it

This should be fixed with 6d3a538525d2eab10bd59400ee1fcaf9569bdf79. Thanks @otopba!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephen-workpop picture stephen-workpop  路  4Comments

satyarths picture satyarths  路  3Comments

sungerk picture sungerk  路  3Comments

eldk picture eldk  路  3Comments

rafaelekol picture rafaelekol  路  4Comments