質問編集履歴
1
ソースを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,197 @@
|
|
27
27
|
トップ画面から表示画面への遷移はsegueを使用しています。
|
28
28
|
|
29
29
|
よろしくお願いします。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
/////////////////
|
36
|
+
|
37
|
+
//トップ画面
|
38
|
+
|
39
|
+
/////////////////
|
40
|
+
|
41
|
+
class ViewController: UIViewController {
|
42
|
+
|
43
|
+
@IBOutlet weak var imageView:UIImageView!
|
44
|
+
|
45
|
+
@IBOutlet var button: UIButton!
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
override func viewDidLoad() {
|
50
|
+
|
51
|
+
super.viewDidLoad()
|
52
|
+
|
53
|
+
//背景画像
|
54
|
+
|
55
|
+
imageView.image = UIImage(named:"background.png")
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
/////////////////
|
70
|
+
|
71
|
+
//表示画面
|
72
|
+
|
73
|
+
/////////////////
|
74
|
+
|
75
|
+
class MainViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
|
76
|
+
|
77
|
+
@IBOutlet weak var imageView:UIImageView!
|
78
|
+
|
79
|
+
@IBOutlet var beforeButton: UIButton!
|
80
|
+
|
81
|
+
@IBOutlet var afterButton: UIButton!
|
82
|
+
|
83
|
+
@IBOutlet weak var beforeText: UILabel!
|
84
|
+
|
85
|
+
@IBOutlet weak var afterText: UILabel!
|
86
|
+
|
87
|
+
//使用変数
|
88
|
+
|
89
|
+
var uiImage:UIImage!
|
90
|
+
|
91
|
+
var uiImage_bk:UIImage!
|
92
|
+
|
93
|
+
var methodValue=0
|
94
|
+
|
95
|
+
//フラグ
|
96
|
+
|
97
|
+
var image_flg = false
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
override func viewDidLoad() {
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
super.viewDidLoad()
|
106
|
+
|
107
|
+
//画像読込
|
108
|
+
|
109
|
+
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
// 写真を選ぶビュー
|
114
|
+
|
115
|
+
let photoView = UIImagePickerController()
|
116
|
+
|
117
|
+
// 写真の選択元をカメラロールにする
|
118
|
+
|
119
|
+
// 「.camera」にすればカメラを起動できる
|
120
|
+
|
121
|
+
photoView.sourceType = .photoLibrary
|
122
|
+
|
123
|
+
// デリゲート
|
124
|
+
|
125
|
+
photoView.delegate = self
|
126
|
+
|
127
|
+
// ビューに表示
|
128
|
+
|
129
|
+
self.present(photoView, animated: true)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
extension MainViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
142
|
+
|
143
|
+
// 写真を選んだ後に呼ばれる処理
|
144
|
+
|
145
|
+
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
if isProcessing == false {
|
152
|
+
|
153
|
+
isProcessing = true
|
154
|
+
|
155
|
+
//画像サイズ
|
156
|
+
|
157
|
+
let IMAGE_MAX_SIZE = 1000.0
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
// 選択した写真を取得する
|
162
|
+
|
163
|
+
let tmpImage = info[.originalImage] as! UIImage
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
//let Resize:CGSize = CGSize.init(width: tmpImage.size.width, height:tmpImage.size.height)
|
168
|
+
|
169
|
+
var tmpSize = Double(tmpImage.size.width)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
if(Double(tmpImage.size.width) > IMAGE_MAX_SIZE || Double(tmpImage.size.height) > IMAGE_MAX_SIZE){
|
174
|
+
|
175
|
+
if(tmpImage.size.width >= tmpImage.size.height){
|
176
|
+
|
177
|
+
tmpSize = IMAGE_MAX_SIZE
|
178
|
+
|
179
|
+
}else{
|
180
|
+
|
181
|
+
tmpSize = IMAGE_MAX_SIZE*Double(tmpImage.size.width/tmpImage.size.height)
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
// ビューに表示する
|
188
|
+
|
189
|
+
let resize_tmpImage:UIImage = resize(image: tmpImage,width: floor(tmpSize))
|
190
|
+
|
191
|
+
let result = UIImage(cgImage: RBGImage(data: pixels, width: Int(resize_tmpImage.size.width), height:Int(resize_tmpImage.size.height))!)
|
192
|
+
|
193
|
+
uiImage = result
|
194
|
+
|
195
|
+
uiImage_bk = result
|
196
|
+
|
197
|
+
imageView.image = result
|
198
|
+
|
199
|
+
if(uiImage.size.width>0){
|
200
|
+
|
201
|
+
image_flg = true
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
// 写真を選ぶビューを引っ込める
|
206
|
+
|
207
|
+
self.dismiss(animated: true)
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
```
|