luberda-molinet / FFImageLoading

Image loading, caching & transforming library for Xamarin and Windows
MIT License
1.42k stars 377 forks source link

How to display SVG file at Android splashscreen ? #437

Closed tematim closed 7 years ago

tematim commented 7 years ago

Hello,

I have a PCL lib with android and ios project.

To have the same code base, this is the example I took : http://www.c-sharpcorner.com/uploadfile/oussamaalrifai/xamarin-forms-android-workaround-for-splash-screen-with-lo/

As you can see, there is a logo, and I want to replace it with an svg. All examples are in xaml file, and here it's an axml file.

Could you help me ?

Regards

daniel-luberda commented 7 years ago

You should do exactly the same, but load image with FFImageLoading native loader from code behind:

ImageService.Instance
    .LoadCompiledResource("file.svg")
    .WithCustomDataResolver(new SvgDataResolver(200, 0, true))
    .Into(imageView);

where imageView is your ImageViewAsync control (important: https://github.com/luberda-molinet/FFImageLoading/wiki/Android-API#imageviewasync)

tematim commented 7 years ago

Ok, I try your code.

This is my activity : ` [Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class SplashActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);

        ImageService.Instance
        .LoadCompiledResource("file.svg")
        .WithCustomDataResolver(new SvgDataResolver(200, 0, true))
        .Into();

        SetContentView(Resource.Layout.SplashLayout);

        System.Threading.ThreadPool.QueueUserWorkItem(o => LoadActivity());
    }

    private void LoadActivity()
    {
        System.Threading.Thread.Sleep(5000); // Simulate a long pause
        RunOnUiThread(Start);
    }

    private void Start()
    {
        var intent = new Intent(this, typeof(MainActivity));
        StartActivity(intent);
    }
}`

My layout : <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" android:adjustViewBounds="true" android:src="@drawable/splash" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:id="@+id/today" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="center_horizontal" android:paddingTop="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold|italic" android:textColor="@color/splashscreen" android:text="a" android:textSize="24sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/splashscreen" android:textStyle="italic" android:text="b" android:textSize="24sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" /> <ImageView android:id="@+id/logoView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/vostMin" android:layout_marginTop="120dp" android:minWidth="900dp" android:minHeight="400dp" android:scaleType="fitXY" android:cropToPadding="true" /> </RelativeLayout> </LinearLayout> </FrameLayout>

My theme : `<?xml version="1.0" encoding="utf-8" ?>

` My resources : ` #FFEE58 ` I can't load the svg to the current layout. Is it possible to help me ?
tematim commented 7 years ago

Hello,

Please reopen the issue, I added some code.

I can’t display any svg at splashscreen

De : Daniel Luberda notifications@github.com Répondre à : luberda-molinet/FFImageLoading reply@reply.github.com Date : jeudi 5 janvier 2017 17:45 À : luberda-molinet/FFImageLoading FFImageLoading@noreply.github.com Cc :, Author author@noreply.github.com Objet : Re: [luberda-molinet/FFImageLoading] How to display SVG file at Android splashscreen ? (#437)

Closed #437https://github.com/luberda-molinet/FFImageLoading/issues/437.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/luberda-molinet/FFImageLoading/issues/437#event-912911917, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOUy9BhCVQuprLCkxr5JjDQnr3KTOnFtks5rPR4ugaJpZM4Lb170.

daniel-luberda commented 7 years ago

Into must have a correct parameter (ImageViewAsync instance), in your code it doesn't have any. Why? Should be this:

        ImageService.Instance
        .LoadCompiledResource("file.svg")
        .WithCustomDataResolver(new SvgDataResolver(200, 0, true))
        .Into(imageView);

Also FFImageLoading support ImageViewAsync, not ImageView on Android. It should be something like this:

<ffnamespace:ImageViewAsync android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" android:adjustViewBounds="true" /> 
molinch commented 7 years ago

@daniel-luberda Maybe we could make a check, then throw a dedicated exception when it's not a ImageViewAsync. What do you think?

daniel-luberda commented 7 years ago

@molinch That's a good idea, but I am wondering where as all Into method take ImageViewAsync as a parameter, so it's impossible to make a mistake.

molinch commented 7 years ago

You are right :) Forget about what I said :+1:

tematim commented 7 years ago

Hello,

I manage to display my svg.

Now I have an issue with his size and "resolution".

I want it to be cut at the left and rigth, and be without pixels.

vostLogo - Copy.zip

I try to change the width and height with same value inside the SvgDataResolver, but the image contain some pixels.

Is it possible to help me ?

daniel-luberda commented 7 years ago

@tematim You should set correct vectorWidth/vectorHeight values. That's all.