微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 FFImageLoading 使用 Xamarin Forms 5

如何解决如何使用 FFImageLoading 使用 Xamarin Forms 5

我正在尝试像这样使用 FFImageLoading:

AppDelegate:

CachedImageRenderer.Init();
CachedImageRenderer.InitimageSourceHandler();
var config = new FFImageLoading.Config.Configuration()
{
    VerboseLogging = true,VerbosePerformanceLogging = false,VerboseMemoryCacheLogging = false,VerboseLoadingCancelledLogging = false
};
ImageService.Instance.Initialize(config);
var ignore = typeof(FFImageLoading.Svg.Forms.SvgCachedImage);

预加载

    public void PreloadImages()
    {
        try
            var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            foreach (var r in resources)
            {
                if (!r.EndsWith(".svg")) continue;
                try
                {
                    var assemblyName = Application.Current?.GetType()?.GetTypeAssemblyFullName();
                    ImageService.Instance.LoadEmbeddedResource($"resource://{r}?assembly={Uri.EscapeUriString(assemblyName)}")
                    //ImageService.Instance.LoadEmbeddedResource($"resource://{r}?assembly={Assembly.GetExecutingAssembly().GetName().Name}")
                    .Success((info,result) =>
                    {
                        Debug.WriteLine($"preloading success! Key: {info.CacheKey}");
                    })
                    .Preload();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"LoaderPage.PreloadImages[{r}]",ex);
                }
            }
    }

代码运行时,图像出现在屏幕上,但我的应用程序输出填充了如下消息:

System.BadImageFormatException: Can't read image size properties. File corrupted?
  at FFImageLoading.Decoders.GifDecoder.sourceRegfToDecodedImageAsync (Foundation.NSData nsdata,CoreGraphics.CGSize destSize,System.nfloat destScale,FFImageLoading.Config.Configuration config,FFImageLoading.Work.TaskParameter parameters,FFImageLoading.Decoders.GifDecoder+RCTResizeMode resizeMode,FFImageLoading.Work.Imageinformation imageinformation,System.Boolean allowUpscale) [0x00068] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Decoders\GifDecoder.cs:62 
  at FFImageLoading.Decoders.GifDecoder.DecodeAsync (System.IO.Stream stream,System.String path,FFImageLoading.Work.ImageSource source,FFImageLoading.Work.Imageinformation imageinformation,FFImageLoading.Work.TaskParameter parameters) [0x000e4] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Decoders\GifDecoder.cs:45 
  at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,timageContainer,timageView].GenerateImageAsync (System.String path,System.IO.Stream imageData,System.Boolean enableTransformations,System.Boolean isPlaceholder) [0x0007c] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:337 
  at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,timageView].RunAsync () [0x0047c] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:643
2021-02-24 01:50:30.338196+0900 Memorise.iOS[41119:898256] Image loading Failed: resource://Memorise.Resources.Cards.pause_Light.svg?assembly=Memorise,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null
System.BadImageFormatException: Can't read image size properties. File corrupted?

请注意,有些 SVG 非常简单,我不知道它们为什么或如何损坏,并且确实会显示在屏幕上。

有没有人能够让预加载工作。请注意,我尝试了两种不同的方法来做 LoadEmbeddedResource,但都没有奏效。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。