【问题标题】:How to rapid load image gif use FFImageLoading in Xamarin Forms?如何在 Xamarin Forms 中使用 FFImageLoading 快速加载图像 gif?
【发布时间】:2018-11-17 20:00:59
【问题描述】:

我的 Gif 图片大小为 2 MB。我使用 Xamarin Forms 的库 FFImageLoading 来加载它。但时间负载超过7秒。 如何快速加载gif图片?

我目前正在使用路径图片:

<ffimageloading:SvgCachedImage HorizontalOptions="Center" VerticalOptions="Center" Aspect="AspectFill" x:Name="Gif" Source="{Binding image}" Margin="0"/>

而 Gif 图像的名称是:

image = "GifImage.gif"

用户迫不及待地加载图像 gif。 所以,请支持我如何在 Xamarin Forms 上快速加载 gif 图像。

谢谢!

【问题讨论】:

    标签: c# .net xamarin xamarin.forms


    【解决方案1】:

    您可以使用 WebView 加载快速 Gif 图像。 使用 WebView 不需要设置任何库。 我用它来替换库FFImageLoading。 它创建一个包含 Gif 图像的 .html,因此加载速度非常快。 您可以在以下位置参考使用它: WebView Gif Viewer

    【讨论】:

      【解决方案2】:

      在 Xamarin 表单上使用 WebView:

      在文件.xaml添加源:

                  <WebView HorizontalOptions="Center"
                       VerticalOptions="Center"
                       HeightRequest="{Binding HeightImage}"
                       WidthRequest="{Binding WidthImage}"
                       Source="{Binding LinkImageGif}" />
      

      在文件.cs添加源:

                  int imageHeight = HeightImage;
                  int imageWidth = WidthImage;
      
                  var source = new HtmlWebViewSource
                  {
                      Html = $"<body\"><img src=\"{_srcImage}\" alt=\"A Gif file\" width=\"{imageWidth}\" height=\"{imageHeight}\" style=\"width: 100%; height: auto;\"/></body>",
                      BaseUrl = DependencyService.Get<IBaseUrl>().Get()
                  };
      

      因为Android和iOS的BaseUrl是不同的。所以,使用 Share Project,创建一个依赖。

      首先,创建一个Interface

      namespace abcxyz
      {
          public interface IBaseUrl { string Get(); }
      }
      

      在Android的依赖,添加代码:

      [assembly: Dependency(typeof(BaseUrlAndroid))]
      namespace abcxyz
      {
          public class BaseUrlAndroid : IBaseUrl
          {
              public string Get() => "file:///android_asset/";
          }
      }
      

      (Gif 图片将添加到文件夹:AndroidResource 的资产)

      在iOS的依赖,添加代码:

      [assembly: Dependency(typeof(BaseUrlOniOs))]
      namespace abcxyz
      {
          public class BaseUrlOniOs : IBaseUrl
          {
              public string Get()
              {
                  return NSBundle.MainBundle.BundlePath;
              }
          }
      }
      

      (Gif图片将添加到iOS的ResourceBundleResource)文件夹)

      【讨论】:

        猜你喜欢
        • 2017-08-03
        • 1970-01-01
        • 2018-07-12
        • 2019-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-22
        • 1970-01-01
        相关资源
        最近更新 更多