質問編集履歴
1
変数名の誤りなどの雑なコードを修正しました。申し訳ありません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
//インスタンス変数
|
14
14
|
|
15
|
-
var myImageView = UII
|
15
|
+
var myImageView = UIImageView()
|
16
16
|
|
17
17
|
|
18
18
|
|
@@ -38,7 +38,11 @@
|
|
38
38
|
|
39
39
|
myImageView.userInteractionEnabled = true
|
40
40
|
|
41
|
-
myImage.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tapAction:"))
|
41
|
+
myImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tapAction:"))
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
self.view.addSubview(myImageView)
|
42
46
|
|
43
47
|
}
|
44
48
|
|
@@ -50,19 +54,21 @@
|
|
50
54
|
|
51
55
|
//タップした座標の取得
|
52
56
|
|
53
|
-
let tapPoint = sender.locationInView(self.myImageView)
|
57
|
+
let tapPoint = sender.locationInView(self.myImageView)
|
54
58
|
|
55
|
-
//imageをdata化
|
59
|
+
//imageをdata化
|
56
60
|
|
57
|
-
let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(my
|
61
|
+
let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(myImageView.image!.CGImage))
|
58
62
|
|
59
|
-
let data: UnsafePointer = CFDataGetBytePtr(pixelData)
|
63
|
+
let data: UnsafePointer = CFDataGetBytePtr(pixelData)
|
60
64
|
|
61
65
|
|
62
66
|
|
63
67
|
//タップした位置の座標にあたるアドレスを算出
|
64
68
|
|
65
|
-
let pixelAd: Int = ((Int(my
|
69
|
+
let pixelAd: Int = ((Int(myImageView.image!.size.width) * Int(tapPoint.y)) + Int(tapPoint.x)) * 4
|
70
|
+
|
71
|
+
|
66
72
|
|
67
73
|
//それぞれRGBAの値をとる
|
68
74
|
|
@@ -94,29 +100,29 @@
|
|
94
100
|
|
95
101
|
//モノクロのフィルターを指定
|
96
102
|
|
97
|
-
let
|
103
|
+
let myFilter = CIFilter(name: "CIColorMonochrome")
|
98
104
|
|
99
|
-
|
105
|
+
myFilter!.setValue(CIImage(image: myImageView.image!), forKey: kCIInputImageKey)
|
100
106
|
|
101
|
-
//値の調整.
|
107
|
+
//値の調整.
|
102
108
|
|
103
|
-
|
109
|
+
myFilter!.setValue(CIColor(red: 0.5, green: 0.5, blue: 0.5), forKey: kCIInputColorKey)
|
104
110
|
|
105
|
-
|
111
|
+
myFilter!.setValue(1.0, forKey: kCIInputIntensityKey)
|
106
112
|
|
107
|
-
// フィルターを通した画像をアウトプット.
|
113
|
+
// フィルターを通した画像をアウトプット.
|
108
114
|
|
109
|
-
let myOutputImage : CIImage = my
|
115
|
+
let myOutputImage : CIImage = myFilter!.outputImage!
|
110
116
|
|
111
|
-
let context = CIContext(options: nil)
|
117
|
+
let context = CIContext(options: nil)
|
112
118
|
|
113
|
-
let cgImage = context.createCGImage(myOutputImage, fromRect: myOutputImage.extent)
|
119
|
+
let cgImage = context.createCGImage(myOutputImage, fromRect: myOutputImage.extent)
|
114
120
|
|
115
|
-
let newImage = UIImage(CGImage: cgImage)
|
121
|
+
let newImage = UIImage(CGImage: cgImage)
|
116
122
|
|
117
|
-
// 再びUIViewにセット.
|
123
|
+
// 再びUIViewにセット.
|
118
124
|
|
119
|
-
self.
|
125
|
+
self.myImageView.image = newImage
|
120
126
|
|
121
127
|
```
|
122
128
|
|
@@ -137,3 +143,7 @@
|
|
137
143
|
どなたかお知恵を拝借できれば幸いです。
|
138
144
|
|
139
145
|
長文失礼しました。
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
雑なコードで申し訳ございませんでした。修正しました。
|