Fresco: centerCrop does not work

Created on 27 Aug 2016  路  18Comments  路  Source: facebook/fresco

I am setting a local Uri for the image for the Drawee and once the image loads, it doesn't centerCrop.

When the image is not square, there is always one side that is smaller than the respective width/height as if no scaling type was being applied and the default fitCenter was being used.

I'm also using fresco's scaleType as opposed to android:scaleType since I read the Android property is just ignores by Fresco.

bug needs-details

Most helpful comment

Where release is this fixed in?
It still happening in fresco:1.5.0 a year after being reported.

All 18 comments

I can add my code and screenshot but I don't do anything fancy, so it seems like a legitimate issue with the library's handling of scaleType

It works for me as expected. Example:

XML:

<com.facebook.drawee.view.SimpleDraweeView
  android:id="@+id/sdv"
  android:layout_width="64dp"
  android:layout_height="128dp"
  />

Java:

SimpleDraweeView sdv = (SimpleDraweeView) findViewById(R.id.sdv);
sdv.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
sdv.setImageURI(uri);

Tested with remote and local image in raw directory, 600x400px

Hmm I set the scaleType via XML; does that make a difference? Maybe it's an edge case - I'll work through my own code and deconstruct what the core issue may be

Yep - verified that setting the xml property does not center crop. Setting is programmatically as you have shown works, however.

Keep in mind that in order for this to work in XML, you have to use

<com.facebook.drawee.view.SimpleDraweeView
    android:id="..."
    android:layout_width="..."
    android:layout_height="..."
    app:actualImageScaleType="centerCrop"
    />

where xmlns:app="http://schemas.android.com/apk/res-auto", see http://frescolib.org/docs/using-drawees-xml.html and http://frescolib.org/docs/scaling.html

Then it should also work in XML.

I believe that's exactly what I've done here with @+id/background_image

screenshot 2016-08-28 14 16 01

Changing the scale type in XML works for me as expected. Maybe you set a custom DraweeHierachy (which overwrites the XML values)?

I don't see anything I'm doing that would suggest that?
screenshot 2016-08-28 14 45 48
these are the only lines in which I'm interacting with the SimpleDraweeView

Also, the default scale type used is CENTER_CROP, so not specifying anything should also give the correct results.

setImageBitmap should not be used with Fresco. Another reason why this is not working could be your custom layout params.

1486 I have the same problem,I don't know what is making this problem. @eddieberklee could you find any solutions?

How do you use Fresco? Could you provide a minimal example where we can reproduce the problem?

I have updated the refrenced question..

I also faced this issue. CenterCrop has no effect for the same image if it is loaded from a local file path. After changing to an web url it worked fine. Looks like the issue is reproducible only for local images.

We'll look into it.

Also had the same issue:

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/nav_header_background"
        tools:background="@color/accent_color"
        android:contentDescription="@null"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/nav_drawer_banner_height"
        app:backgroundImage="@drawable/splash_image"
        app:actualImageScaleType="centerCrop"
        app:viewAspectRatio="1.5"/>

It's inside a RelativeLayout, and it is not modified in code.

Emulator - Nexus One API 19

Original:
splash_image

InView:
screen shot 2017-02-16 at 10 16 03 am

Where release is this fixed in?
It still happening in fresco:1.5.0 a year after being reported.

@bpappin could you reproduce this in the showcase app? I tested with Media Provider example to use a local image (DraweeMediaPickerFragment.java) but I cannot reproduce it, also tried with RelativeLayout and it is also working fine.

Are you sure you're setting the image using setImageURI() method?

i have the same problem ,is there any solution?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liubaoyua picture liubaoyua  路  3Comments

stevenmtang picture stevenmtang  路  3Comments

sungerk picture sungerk  路  3Comments

amodkanthe picture amodkanthe  路  3Comments

kingty picture kingty  路  4Comments