質問編集履歴
1
Error
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GLKTextureLoader
|
1
|
+
Error Domain=GLKTextureLoaderErrorDomain Code=12
|
test
CHANGED
@@ -1,131 +1 @@
|
|
1
|
-
GLKTextureLoader.textureでnullが帰って来てエラーになります。
|
2
|
-
|
3
|
-
どのようにして取得すれば良いでしょうか?
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
エラーメッセージ
|
8
|
-
|
9
|
-
```
|
10
|
-
|
11
1
|
Error Domain=GLKTextureLoaderErrorDomain Code=12 "(null)" UserInfo={GLKTextureLoaderErrorKey=Image decoding failed}
|
12
|
-
|
13
|
-
```
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
コード
|
18
|
-
|
19
|
-
```swift
|
20
|
-
|
21
|
-
import Cocoa
|
22
|
-
|
23
|
-
import CoreImage
|
24
|
-
|
25
|
-
import GLKit
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
func toCGImage(image: NSImage) -> CGImage?{
|
30
|
-
|
31
|
-
var imageRect:CGRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
|
32
|
-
|
33
|
-
let aCGImage = image.cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
|
34
|
-
|
35
|
-
return aCGImage
|
36
|
-
|
37
|
-
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
let simpleattr: [NSOpenGLPixelFormatAttribute] = [
|
42
|
-
|
43
|
-
NSOpenGLPixelFormatAttribute(NSOpenGLPFADoubleBuffer),
|
44
|
-
|
45
|
-
NSOpenGLPixelFormatAttribute(NSOpenGLPFAAccelerated),
|
46
|
-
|
47
|
-
NSOpenGLPixelFormatAttribute(0)
|
48
|
-
|
49
|
-
]
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
let pf = NSOpenGLPixelFormat(attributes: simpleattr)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
let image1 = NSImage(byReferencingFile: "/Users/xxx/Pictures/スクリーンショット1.png")!
|
58
|
-
|
59
|
-
let image2 = NSImage(byReferencingFile: "/Users/xxx/Pictures/スクリーンショット2.png")!
|
60
|
-
|
61
|
-
let overlayImage:CIImage = CIImage(cgImage: toCGImage(image: image1)!)
|
62
|
-
|
63
|
-
let backgroundImage:CIImage = CIImage(cgImage: toCGImage(image: image2)!)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
let alpha:CGFloat = 0.8
|
68
|
-
|
69
|
-
let rgba:[CGFloat] = [0.0, 0.0, 0.0, alpha]
|
70
|
-
|
71
|
-
let colorMatrix:CIFilter = CIFilter(name: "CIColorMatrix")!
|
72
|
-
|
73
|
-
colorMatrix.setDefaults()
|
74
|
-
|
75
|
-
colorMatrix.setValue(overlayImage, forKey: kCIInputImageKey)
|
76
|
-
|
77
|
-
let vector = CIVector(values: rgba, count: 4)
|
78
|
-
|
79
|
-
colorMatrix.setValue(vector, forKey: "inputAVector")
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
let composite:CIFilter = CIFilter(name: "CISourceOverCompositing")!
|
84
|
-
|
85
|
-
composite.setDefaults()
|
86
|
-
|
87
|
-
composite.setValue(colorMatrix.outputImage, forKey: kCIInputImageKey)
|
88
|
-
|
89
|
-
composite.setValue(backgroundImage, forKey: kCIInputBackgroundImageKey)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
let outputImage:CIImage = composite.outputImage!
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
let context:CIContext = CIContext.init(options: nil)
|
98
|
-
|
99
|
-
let pixelData = context.createCGImage(outputImage, from: outputImage.extent)!
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
let glContext:NSOpenGLContext = NSOpenGLContext(format: pf!, share: nil)!
|
104
|
-
|
105
|
-
glContext.makeCurrentContext()
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
var texture:GLKTextureInfo
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
do {
|
114
|
-
|
115
|
-
//失敗する。
|
116
|
-
|
117
|
-
texture = try GLKTextureLoader.texture(with: pixelData, options: nil)
|
118
|
-
|
119
|
-
} catch {
|
120
|
-
|
121
|
-
//ここに来る。
|
122
|
-
|
123
|
-
print(error)
|
124
|
-
|
125
|
-
exit(0)
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
![スクリーンショット](a021d9d62b429d990b696cb0d6147342.png)
|