Ffimageloading: [Android] Broken Image with AspectFill

Created on 9 Nov 2018  路  17Comments  路  Source: luberda-molinet/FFImageLoading

Description

Can you check this issue ?
Because now it's working with Xamarin.Forms Image but it's still not working with CachedImage. Thanks :)

Most helpful comment

For those who can't waiting for the official update, base on @velocitysystems solution, you can add this renderer

using System;
using Android.Content;
using Android.Graphics;
using Android.Runtime;
using Project.Droid.Renderers;
using FFImageLoading.Forms;
using FFImageLoading.Forms.Platform;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(CachedImage), typeof(FFImage_CachedImageRenderer))]
namespace Project.Droid.Renderers
{
    class FFImage_CachedImageRenderer : CachedImageFastRenderer
    {

        public FFImage_CachedImageRenderer(Context context) : base(context)
        {
        }

        public FFImage_CachedImageRenderer(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
        {
        }

        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);
            ClipBounds = GetScaleType() == ScaleType.CenterCrop ? new Rect(0, 0, right - left, bottom - top) : null;
        }

    }
}

All 17 comments

Hello, I'm having this issue too with latest stable FFImageLoading (2.4.4.859) and Xamarin Forms 3.4.0.1008975.

See screenshots:

Android:
android

iOS:
ios

Better use Xamarin Forms Image now until the problem solved

Hmmm... I can't because I need the DownsampleToViewSize functionality from FFImageLoading to release pressure on memory (I don't have thumbnails available).

I'd be better off downgrading Xamarin Forms & FFImageLoading altogether, but that's a pain too...

Daniel, any idea?

Sure, you can downgrade. In my case I can't downgrade because I need TitleView with Command Binding

Broken Aspect Fill + No Background Color.

Simplest project VS 15.9.2

<StackLayout>
    <ffimageloading:CachedImage 
        Margin="10"    HeightRequest="100"   WidthRequest="100"
        Aspect="AspectFit" 
    HorizontalOptions="Center" VerticalOptions="Center"
        BackgroundColor="Gray"/>        

    <ffimageloading:CachedImage 
        Margin="10"   HeightRequest="50"   WidthRequest="100"
        Aspect="AspectFill" 
    Source="xam_icon.png" HorizontalOptions="Center" VerticalOptions="Center"
        BackgroundColor="Gray"/> 

    <ffimageloading:CachedImage 
        Margin="10"   HeightRequest="100"   WidthRequest="100"
        Aspect="Fill"  HorizontalOptions="Center" VerticalOptions="Center"
        BackgroundColor="Gray"/>
</StackLayout>

Xamarin Forms 3.1 + FFImage 2.4.2 = OK

test1

Xamarin Forms 3.4 + FFImage 2.4.4.859 & 860_pre =

test2

Between this versions - initialization errors only .

Hi Daniel,

Could you have a look at this one?

This issue is blocking me from releasing my app :/

At least unless I painfully downgrade every component...

Would be very appreciated.

Thanks

Hi @daniel-luberda ,
Could you check this?

Hi, I have the same issue (last version of XF and FFImageLoading). Did someone find any workaround other than downgrading or using xamarin image control ?

Unfortunately no.
As this is only happening with Android, I'm still waiting for @daniel-luberda to take a look at this one...

@daniel-luberda @nbsoftware I have a PR up for this now which brings over the fix from XF.

Thanks for your effort @velocitysystems :)
Please do an update @daniel-luberda

For those who can't waiting for the official update, base on @velocitysystems solution, you can add this renderer

using System;
using Android.Content;
using Android.Graphics;
using Android.Runtime;
using Project.Droid.Renderers;
using FFImageLoading.Forms;
using FFImageLoading.Forms.Platform;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(CachedImage), typeof(FFImage_CachedImageRenderer))]
namespace Project.Droid.Renderers
{
    class FFImage_CachedImageRenderer : CachedImageFastRenderer
    {

        public FFImage_CachedImageRenderer(Context context) : base(context)
        {
        }

        public FFImage_CachedImageRenderer(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
        {
        }

        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);
            ClipBounds = GetScaleType() == ScaleType.CenterCrop ? new Rect(0, 0, right - left, bottom - top) : null;
        }

    }
}

@rredoh To use your workaround, you'll also need to:

  1. Add this to your renderer:
public static void OverrideDefaultFastRenderer()
{
    var assembly = typeof(Xamarin.Forms.Image).Assembly;
    Type registrarType = assembly.GetType("Xamarin.Forms.Internals.Registrar") ?? assembly.GetType("Xamarin.Forms.Registrar");
    var registrarProperty = registrarType.GetProperty("Registered", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

    var registrar = registrarProperty.GetValue(registrarType, null);
    var registerMethod = registrar.GetType().GetRuntimeMethod("Register", new[] { typeof(Type), typeof(Type) });
    registerMethod.Invoke(registrar, new[] { typeof(CachedImage), typeof(FFImage_CachedImageRenderer) });
}
  1. Call OverrideDefaultFastRenderer after calling CachedImageRenderer.Init:
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer);
FFImage_CachedImageRenderer.OverrideDefaultFastRenderer();

Thanks @velocitysystems :)

I can confirm it works as expected with this workaround.
Thanks!!

Is this in preview? The image is still bleeding out of it's view with DownSampleToViewSize prop enabled. I have version 2.4.4.859

Was this page helpful?
0 / 5 - 0 ratings