luberda-molinet / FFImageLoading

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

Not a valid bitmap when I try to preload SVG #914

Closed WilliamWatterson86 closed 6 years ago

WilliamWatterson86 commented 6 years ago

Description

I have a content page where I am loading an SVG image. The image loads and displays on screen - however the first time the app is loaded it takes a second or two for the image to appear. So I tried using this:

ImageService.Instance.LoadEmbeddedResource("SVGImages.temp-circle.svg", typeof(App).GetTypeInfo().Assembly).Preload();

But using this I am getting the error below: System.BadImageFormatException: Not a valid bitmap

Is there something different I have to do in order to preload the SVG and stop the screen flicker on the first load of the page?

Steps to Reproduce

Expected Behavior

Actual Behavior

Basic Information

Screenshots

Reproduction Link / Code

MarcosCobena commented 6 years ago

It happens the same for me, although I'm referencing the image directly from XAML.

MarcosCobena commented 6 years ago

Hey! Got it working, double check the SVG appears in this way in your CSPROJ —try moving it to Android's Resources just the assure in this way works:

<AndroidResource Include="Resources\drawable\icon_nfc.svg" />

, and that you follow the guideline when installing the NuGet packages:

https://github.com/luberda-molinet/FFImageLoading/wiki/SVG-support#xamarinforms

It should work.

daniel-luberda commented 6 years ago

You should use:

ImageService.Instance.LoadEmbeddedResource("SVGImages.temp-circle.svg", typeof(App).GetTypeInfo().Assembly)
    .WithCustomDataResolver(new SvgDataResolver(0, yourImageSizeHeight, true))
    .Preload(); 

It's all described here: https://github.com/luberda-molinet/FFImageLoading/wiki/SVG-support#native Also don't forget to set exact size for your image view HeightRequest= yourImageSizeHeight or use custom cache key