【发布时间】:2014-09-30 08:58:00
【问题描述】:
在我的 iOS 应用程序中使用 Google WebP 图像格式时,我发现 Google 的库擅长在本机代码中显示 WebP 图像。
现在我也想在我的 webapp 中使用 WebP,但 UIWebView 不支持。有什么想法可以实现吗?
【问题讨论】:
在我的 iOS 应用程序中使用 Google WebP 图像格式时,我发现 Google 的库擅长在本机代码中显示 WebP 图像。
现在我也想在我的 webapp 中使用 WebP,但 UIWebView 不支持。有什么想法可以实现吗?
【问题讨论】:
如果您使用的是 Cordova/Phonegap,有一个插件可以将 WebP 支持添加到 UIWebView。如果您不使用 Cordova,您应该能够使用相同的机制,而无需注册插件。
【讨论】:
您可以使用 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
})
【讨论】:
您可以使用 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
}
【讨论】:
如果您的资源在您的捆绑包中,您可以使用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)
【讨论】: