質問編集履歴

2

2017/01/25 07:31

投稿

konryu304
konryu304

スコア8

test CHANGED
@@ -1 +1 @@
1
- iOS PDFファイルのカラースペースの設定について
1
+ iOS UIImageのカラースペースの設定について
test CHANGED
File without changes

1

2017/01/25 07:31

投稿

konryu304
konryu304

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,16 +1,10 @@
1
1
  ###前提・実現したいこと
2
2
 
3
- iOSアプリにてPDFファイル作成しました。
3
+ iOSアプリにてUIImageのカラースペース変更を行いました。
4
4
 
5
- 際にiOSカメラにて写真取得した画像(UIImage)を使用しております。
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
- PDFのカラースペース変更できずに困っております。
17
+ 画像上下逆となっています。
24
18
 
25
19
  ```
26
20
 
@@ -30,53 +24,67 @@
30
24
 
31
25
  ```Objective-C
32
26
 
33
-
34
-
35
- -(NSData *)createPDFfromUIView
27
+ - (UIImage *)convertImageToGrayScale:(UIImage *)image
36
28
 
37
29
  {
38
30
 
39
- //PDFデータを格納する、NSData配列を作成
31
+ // Create image rectangle with current image width/height
40
32
 
41
- NSMutableData *pdfData = [NSMutableData data];
42
-
43
- CGContextRef pdfContext = UIGraphicsGetCurrentContext();
33
+ CGRect imageRect = CGRectMake(0, 0, 733, 550);//733, 550
44
34
 
45
35
 
46
36
 
47
- //1枚目
37
+ // DeviceRGB color space
48
38
 
49
- UIGraphicsBeginPDFContextToData(pdfData, imageView.bounds, nil);
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
- UIGraphicsBeginPDFPageWithInfo(imageView2.bounds, nil);
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
- UIGraphicsEndPDFContext();
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 pdfData;
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
- 上記のソースコードでPDFを作成しました。
95
+ 上記のソースコードでuiimageを作成しました。
88
96
 
89
97
 
90
98