回答編集履歴
1
追記
test
CHANGED
@@ -10,4 +10,68 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
にすれば動くかもしれません。
|
13
|
+
~~にすれば動くかもしれません。~~
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
----
|
18
|
+
|
19
|
+
追記:
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
手元で再現しました。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
配列からCGImageを作るときのbytesPerRowの値が元のCGImageと一致しないので、そこが原因だとは思いますが、
|
28
|
+
|
29
|
+
正しい計算式がちょっと調べた程度では出てこなかったので、こんな感じでごまかしました。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```swift
|
34
|
+
|
35
|
+
func RBGImage(data: [UInt8], compatible: CGImage) -> CGImage? {
|
36
|
+
|
37
|
+
let providerRef = CGDataProvider(data: NSData(bytes: data, length: data.count))
|
38
|
+
|
39
|
+
let cgimage = CGImage(
|
40
|
+
|
41
|
+
width: compatible.width,
|
42
|
+
|
43
|
+
height: compatible.height,
|
44
|
+
|
45
|
+
bitsPerComponent: compatible.bitsPerComponent,
|
46
|
+
|
47
|
+
bitsPerPixel: compatible.bitsPerPixel,
|
48
|
+
|
49
|
+
bytesPerRow: compatible.bytesPerRow,
|
50
|
+
|
51
|
+
space: compatible.colorSpace!,
|
52
|
+
|
53
|
+
bitmapInfo: compatible.bitmapInfo,
|
54
|
+
|
55
|
+
provider: providerRef!,
|
56
|
+
|
57
|
+
decode: nil,
|
58
|
+
|
59
|
+
shouldInterpolate: false,
|
60
|
+
|
61
|
+
intent: .defaultIntent
|
62
|
+
|
63
|
+
)
|
64
|
+
|
65
|
+
return cgimage
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
呼び出し方は
|
74
|
+
|
75
|
+
`let result_pix = RBGImage(data: katati_pixels, compatible: imageResize.cgImage!)`
|
76
|
+
|
77
|
+
でOKです。
|