我想将WKWebView或UIWebView转换为CIImage。我该怎么做呢?
UIGraphicsBeginImageContext(image.extent.size)
self.webview.layer.render(in:UIGraphicsGetCurrentContext()!)
let result: CIImage = CIImage(image:
UIGraphicsGetImageFromCurrentImageContext()!, options: nil)!
UIGraphicsEndImageContext()我这样做了,但它不工作,我希望UIWebView的内容将显示在CIImage中。背景颜色已显示。
发布于 2018-04-18 16:49:31
这可以通过两个步骤来实现:
WKWebView (基类为UIView)转换为UIImageViewview.layer.render(in:UIGraphicsGetCurrentContext()!) UIImage {便利性初始化(视图: UIView) { UIGraphicsBeginImageContext(view.frame.size) extension让image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() self.init(cgImage: image!.cgImage!) }}
UIImage转换为CIImage让ciimage =CIImage(图像:图像)
https://stackoverflow.com/questions/49894971
复制相似问题