質問編集履歴
2
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
iOS
|
1
|
+
iOS UIImageのカラースペースの設定について
|
test
CHANGED
File without changes
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
|
3
|
-
iOSアプリにて
|
3
|
+
iOSアプリにてUIImageのカラースペースを変更を行いました。
|
4
4
|
|
5
|
-
|
5
|
+
カラースペースの変換は行えたのですが、下記のコードを実行すると上下が逆さまの画像が出来上がります。
|
6
6
|
|
7
|
-
作成したPDFファイルを別のシステムにアップロードしたいのですが。カラースペースの値が問題でファイルを読み込めません。(おそらくiOSの標準カラースペースだと読み込めない)
|
8
|
-
|
9
|
-
下記に記載しているソースコードにてPDFファイルを作成しているのですが、
|
10
|
-
|
11
|
-
カラースペースを一般的なsRGBなどに変更したいです。
|
12
|
-
|
13
|
-
|
7
|
+
※画像を回転すれば良いのですが根本的な解決ではないので…
|
14
8
|
|
15
9
|
|
16
10
|
|
@@ -20,7 +14,7 @@
|
|
20
14
|
|
21
15
|
```
|
22
16
|
|
23
|
-
|
17
|
+
画像が上下逆となってしまいます。
|
24
18
|
|
25
19
|
```
|
26
20
|
|
@@ -30,53 +24,67 @@
|
|
30
24
|
|
31
25
|
```Objective-C
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
-(
|
27
|
+
- (UIImage *)convertImageToGrayScale:(UIImage *)image
|
36
28
|
|
37
29
|
{
|
38
30
|
|
39
|
-
//
|
31
|
+
// Create image rectangle with current image width/height
|
40
32
|
|
41
|
-
NSMutableData *pdfData = [NSMutableData data];
|
42
|
-
|
43
|
-
CG
|
33
|
+
CGRect imageRect = CGRectMake(0, 0, 733, 550);//733, 550
|
44
34
|
|
45
35
|
|
46
36
|
|
47
|
-
//
|
37
|
+
// DeviceRGB color space
|
48
38
|
|
49
|
-
|
39
|
+
// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
|
50
40
|
|
51
|
-
UIGraphicsBeginPDFPage();
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
pdfContext = UIGraphicsGetCurrentContext();
|
56
|
-
|
57
|
-
[imageView.layer renderInContext:pdfContext];
|
58
|
-
|
59
|
-
//2枚目
|
60
|
-
|
61
|
-
|
41
|
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
62
|
-
|
63
|
-
[imageView2.layer renderInContext:pdfContext];
|
64
|
-
|
65
|
-
//3枚目
|
66
|
-
|
67
|
-
UIGraphicsBeginPDFPageWithInfo(signatureResizeImage.bounds, nil);
|
68
|
-
|
69
|
-
[signatureResizeImage.layer renderInContext:pdfContext];
|
70
42
|
|
71
43
|
|
72
44
|
|
73
|
-
|
45
|
+
// Create bitmap content with current image size and DeviceRGB colorspace
|
46
|
+
|
47
|
+
CGContextRef context = CGBitmapContextCreate(nil, 733, 550, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
|
74
48
|
|
75
49
|
|
76
50
|
|
51
|
+
// Draw image into current context, with specified rectangle
|
52
|
+
|
53
|
+
// using previously defined context (with DeviceRGB colorspace)
|
54
|
+
|
55
|
+
CGContextDrawImage(context, imageRect, [image CGImage]);
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// Create bitmap image info from pixel data in current context
|
60
|
+
|
61
|
+
CGImageRef imageRef = CGBitmapContextCreateImage(context);
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
// Create a new UIImage object
|
66
|
+
|
67
|
+
UIImage *newImage = [UIImage imageWithCGImage:imageRef];
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// Release colorspace, context and bitmap information
|
72
|
+
|
73
|
+
CGColorSpaceRelease(colorSpace);
|
74
|
+
|
75
|
+
CGContextRelease(context);
|
76
|
+
|
77
|
+
CFRelease(imageRef);
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
// Return the new grayscale image
|
82
|
+
|
77
|
-
return
|
83
|
+
return newImage;
|
78
84
|
|
79
85
|
}
|
86
|
+
|
87
|
+
```
|
80
88
|
|
81
89
|
```
|
82
90
|
|
@@ -84,7 +92,7 @@
|
|
84
92
|
|
85
93
|
###試したこと
|
86
94
|
|
87
|
-
上記のソースコードで
|
95
|
+
上記のソースコードでuiimageを作成しました。
|
88
96
|
|
89
97
|
|
90
98
|
|