-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oct9.swift
44 lines (34 loc) · 1.42 KB
/
Oct9.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import UIKit
import CoreImage
import CoreImage.CIFilterBuiltins
import PlaygroundSupport
class ViewController: UIViewController {
var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.image = UIImage(named: "Bird")
view.addSubview(imageView)
NSLayoutConstraint.activate([
imageView.widthAnchor.constraint(equalToConstant: 300),
imageView.heightAnchor.constraint(equalToConstant: 300),
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
let context = CIContext(options: nil)
let blur = CIFilter.gaussianBlur()
blur.inputImage = CIImage(image: UIImage(named: "Bird")!) // Better to use guard let
blur.radius = 30
if let output = blur.outputImage {
if let cGImage = context.createCGImage(output, from: output.extent) {
let processedImage = UIImage(cgImage: cGImage)
imageView.image = processedImage
}
}
}
}
let main = ViewController()
let nav = UINavigationController(rootViewController: main)
PlaygroundPage.current.liveView = nav