xamarin - 如何使用 FFImageLoading 通过 Xamarin Forms 5 成功缓存和加载 svg 资源
问题描述
我正在尝试像这样使用 FFImageLoading:
应用委托:
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, FFImageLoading.Work.ImageSource source, System.IO.Stream imageData, FFImageLoading.Work.ImageInformation imageInformation, System.Boolean enableTransformations, System.Boolean isPlaceholder) [0x0007c] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:337
at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,TImageContainer,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
但都没有奏效。
解决方案
推荐阅读
- arrays - Go Struct JSON 数组数组
- node.js - Docker - 在 docker 容器日志中找不到模块
- salesforce - 使用 sfdx CLI 将 Salesforce CustomObjects 和 ApexClass 作为代码拉取的问题
- angular - 如何在库 angular 中使用 scss 文件创建组件
- ruby-on-rails - Git lfs mp4文件没有在heroku上播放
- r - 尝试四舍五入减去 r 中的日期
- credit-card - 计费循环商户类别代码导致 CC 付款被拒
- entity-framework - EF Core 5 升级 - 查询超时
- x-frame-options - X-Frame-Options 标头未设置:请问如何设置?
- sql - 从表中选择不同的 ID