簡體   English   中英

iOS:在 UIWebView 中顯示 WebP 圖片

[英]iOS: Display WebP image in UIWebView

在我的 iOS 應用程序中使用 Google WebP 圖像格式時,我發現 Google 的庫擅長在本機代碼中顯示 WebP 圖像。

現在我也想在我的 webapp 中使用 WebP,但 UIWebView 不支持。 任何想法來實施它?

如果你使用 Cordova/Phonegap,有一個插件可以為 UIWebView 添加 WebP 支持。 如果您不使用 Cordova,您應該能夠使用相同的機制,而無需注冊插件。

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

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

從 Web 加載 WebP 圖片真的很容易

使用斯威夫特:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM