question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaling up image with RoundingParams works wrong (Android 9.0)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
oprisnikcommented, Mar 1, 2019

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

0reactions
dmitrychistyakovcommented, Feb 27, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bad image quality after resizing/scaling bitmap - Stack Overflow
Use createScaledBitmap will make your image looks very bad. I've met this problem and I've resolved it. Below code will fix the problem:...
Read more >
Rounded Corners and Circles - Fresco
One workaround is to use a different scale type (e.g. centerCrop) that ensures that the whole view is covered. Another workaround is to...
Read more >
Scaling Images In Android Not Working Like Supposed To ...
Scaling Images In Android Not Working Like Supposed To With Code Solution Hello everyone, in this post we will look at how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found