回答編集履歴
3
追記
test
CHANGED
@@ -87,3 +87,55 @@
|
|
87
87
|
PDFを拡大すると、ちゃんとオリジナルの解像度が維持されていることがわかります。
|
88
88
|
|
89
89
|
![イメージ説明](16e4e10d7cfdf2a6f043a2d533238821.png)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
----
|
94
|
+
|
95
|
+
更に追記:
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
これをPDF作成時に呼んでもらえれば高画質のままPDFに画像が載るはずです。
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
```swift
|
104
|
+
|
105
|
+
/// カレントコンテキストに対してUIImageViewが持つimageをUIImageViewの姿勢のまま描画します。
|
106
|
+
|
107
|
+
private func draw(imageView: UIImageView) {
|
108
|
+
|
109
|
+
guard let image = imageView.image else { return }
|
110
|
+
|
111
|
+
guard let ctx = UIGraphicsGetCurrentContext() else { return }
|
112
|
+
|
113
|
+
let orgTransform = imageView.transform
|
114
|
+
|
115
|
+
imageView.transform = .identity
|
116
|
+
|
117
|
+
let orgFrame = imageView.frame
|
118
|
+
|
119
|
+
imageView.transform = orgTransform
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
ctx.saveGState()
|
124
|
+
|
125
|
+
ctx.translateBy(x: +orgFrame.midX, y: +orgFrame.midY)
|
126
|
+
|
127
|
+
ctx.concatenate(orgTransform)
|
128
|
+
|
129
|
+
ctx.translateBy(x: -orgFrame.midX, y: -orgFrame.midY)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
image.draw(in: orgFrame.aspectFit(contentSize: image.size, stretchble: true, integer: false))
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
ctx.restoreGState()
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
```
|
2
追記
test
CHANGED
@@ -21,3 +21,69 @@
|
|
21
21
|
|
22
22
|
|
23
23
|
#他にもっと簡単な方法があったらすみません...
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
----
|
30
|
+
|
31
|
+
追記:
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
手元でも検証しました。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```swift
|
40
|
+
|
41
|
+
import UIKit
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
class ViewController: UIViewController {
|
46
|
+
|
47
|
+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
48
|
+
|
49
|
+
let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("test.pdf")
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
let bounds = CGRect(x: 0, y: 0, width: 320, height: 480)
|
54
|
+
|
55
|
+
if UIGraphicsBeginPDFContextToFile(path, bounds, nil) {
|
56
|
+
|
57
|
+
UIGraphicsBeginPDFPageWithInfo(bounds, nil)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
let img = UIImage(named: "Hoge")
|
62
|
+
|
63
|
+
img?.draw(in: CGRect(x: 0, y: 0, width: 20, height: 20))
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
UIGraphicsEndPDFContext()
|
68
|
+
|
69
|
+
print("OK: (path)")
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
小さく画像を書き出していますが、
|
82
|
+
|
83
|
+
![イメージ説明](aafe137d2c678e278e95827958aac0ed.png)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
PDFを拡大すると、ちゃんとオリジナルの解像度が維持されていることがわかります。
|
88
|
+
|
89
|
+
![イメージ説明](16e4e10d7cfdf2a6f043a2d533238821.png)
|
1
文章が正しく画面に反映されない
test
CHANGED
@@ -20,4 +20,4 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
#他にもっと簡単な方法があったらすみません
|
23
|
+
#他にもっと簡単な方法があったらすみません...
|