-
Notifications
You must be signed in to change notification settings - Fork 131
/
SwViewController.swift
78 lines (61 loc) · 2.63 KB
/
SwViewController.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// SwViewController.swift
// CVOpenStitch
//
// Created by Foundry on 04/06/2014.
// Copyright (c) 2014 Foundry. All rights reserved.
//
import UIKit
class SwViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet var spinner:UIActivityIndicatorView!
@IBOutlet var imageView:UIImageView?
@IBOutlet var scrollView:UIScrollView!
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
// Custom initialization
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
stitch()
}
func stitch() {
self.spinner.startAnimating()
DispatchQueue.global().async {
let image1 = UIImage(named:"pano_19_16_mid.jpg")
let image2 = UIImage(named:"pano_19_20_mid.jpg")
let image3 = UIImage(named:"pano_19_22_mid.jpg")
let image4 = UIImage(named:"pano_19_25_mid.jpg")
let imageArray:[UIImage?] = [image1,image2,image3,image4]
let stitchedImage:UIImage = CVWrapper.process(with: imageArray as! [UIImage]) as UIImage
DispatchQueue.main.async {
NSLog("stichedImage %@", stitchedImage)
let imageView:UIImageView = UIImageView.init(image: stitchedImage)
self.imageView = imageView
self.scrollView.addSubview(self.imageView!)
self.scrollView.backgroundColor = UIColor.black
self.scrollView.contentSize = self.imageView!.bounds.size
self.scrollView.maximumZoomScale = 4.0
self.scrollView.minimumZoomScale = 0.5
self.scrollView.delegate = self
self.scrollView.contentOffset = CGPoint(x: -(self.scrollView.bounds.size.width - self.imageView!.bounds.size.width)/2.0, y: -(self.scrollView.bounds.size.height - self.imageView!.bounds.size.height)/2.0)
NSLog("scrollview \(self.scrollView.contentSize)")
self.spinner.stopAnimating()
}
}
}
func viewForZooming(in scrollView:UIScrollView) -> UIView? {
return self.imageView!
}
}