【问题标题】:iOS: Display WebP image in UIWebViewiOS:在 UIWebView 中显示 WebP 图像
【发布时间】:2014-09-30 08:58:00
【问题描述】:

在我的 iOS 应用程序中使用 Google WebP 图像格式时,我发现 Google 的库擅长在本机代码中显示 WebP 图像。

现在我也想在我的 webapp 中使用 WebP,但 UIWebView 不支持。有什么想法可以实现吗?

【问题讨论】:

    标签: ios uiwebview webp


    【解决方案1】:

    如果您使用的是 Cordova/Phonegap,有一个插件可以将 WebP 支持添加到 UIWebView。如果您不使用 Cordova,您应该能够使用相同的机制,而无需注册插件。

    https://github.com/dpogue/cordova-plugin-webp

    【讨论】:

      【解决方案2】:

      您可以使用 Pod https://github.com/rs/SDWebImage

      从 Web 加载 WebP 图像真的很容易

      使用 Swift:

      SDWebImageManager.shared().loadImage(with: url, options: .highPriority, progress: nil, completed: {(resultSet) in
                  YOURWEBVIEW.image = resultSet.0
      
              })
      

      【讨论】:

        【解决方案3】:

        您可以使用 Pod https://github.com/rs/SDWebImage

        POD:-pod 'SDWebImage/WebP'

        使用 Swift 4.2:

        let thumbimgurl = URL(string: "https://res.cloudinary.com/demo/image/upload/w_300/sample.webp")
        
        SDWebImageManager.shared().loadImage(with: thumbimgurl, options: .highPriority, progress: nil) { (DisplayUIImage, ImageSize, Error, SDImageCacheType, ImageBool, ImageURL) in
        
        self.MyImageDisplayImageView.image = DisplayUIImage
        
        }
        

        【讨论】:

          【解决方案4】:

          如果您的资源在您的捆绑包中,您可以使用SDWebImage 库以这种方式进行操作:

          let webpData: Data = try Data(contentsOf: Bundle.main.url(forResource: "your_resource_name", withExtension:"webp")!)
          imageView.image = SDImageWebPCoder.shared.decodedImage(with: webpData, options: nil)
          

          【讨论】:

            猜你喜欢
            • 2016-04-23
            • 2020-05-06
            • 1970-01-01
            • 2019-09-20
            • 2021-05-29
            • 2012-07-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多