我正在尝试将CIFilter应用于我的单一视图应用程序中的imageView中已显示的图像,但它似乎没有应用过滤器。有人可以建议吗?我的输入图像看起来完全一样。
(SWIFT):
(?i) -- makes the regex case insensitive
[\s\S] -- is an atom to match any character - even newlines
*? -- match 0 or more, but as few as possible, of the previous atom
( -- start a group that captures all matches until the closing )
(?: -- start a group that doesn't capture it's contents
<|%3C) -- match either a < or %3C (which is the URL-encoded version of <)
(?:\/|%2F)? -- optionally match a / or %2F
[a-z\d]+ -- match one or more letters or numbers
(?:>|%3E) -- match the closing tag
) -- close the open group
CONSOLE:
let filter = CIFilter.init(name: "CIHueAdjust")
let context = CIContext()
var extent: CGRect!
var scaleFactor: CGFloat!
@IBOutlet weak var img: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let ciImage = CIImage.init(image: img.image!)
filter?.setDefaults()
filter?.setValue(ciImage, forKeyPath: kCIInputImageKey)
let result = filter?.outputImage
print("result: \(result)")
var image = UIImage.init(cgImage: context.createCGImage(result!, from: result!.extent)!)
img.image = image
img.image = image
}
答案 0 :(得分:0)
在评论中,但是这里有关于如何使用Swift 4设置对CIHueAdjust
的调用的完整(并且格式更好)的答案:
let filter = CIFilter(name: "CIHueAdjust")
let context = CIContext()
var extent: CGRect!
var scaleFactor: CGFloat!
@IBOutlet weak var img: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let ciImage = CIImage(image: img.image!)
// Note: you may use kCIInputImageKey for inputImage
filter?.setValue(ciImage, forKey: "inputImage")
filter?.setValue(Float(1), forKey: "inputAngle")
let result = filter?.outputImage
var image = UIImage(cgImage: context.createCGImage(result!, from: result!.extent)!)
img.image = image
}