質問編集履歴

1

修正

2017/05/02 01:27

投稿

yukitoto
yukitoto

スコア53

test CHANGED
File without changes
test CHANGED
@@ -15,59 +15,3 @@
15
15
  どのようにすれば、それ以上の圧縮ができるのでしょうか。
16
16
 
17
17
  それともiOS側での処理を諦め、サーバーサイドでの処理が必要になるのでしょうか。
18
-
19
-
20
-
21
- ```
22
-
23
- static func convertToJPEG(image: UIImage, maxBytes: Int = 20000) -> Data? {
24
-
25
- var quality: CGFloat = 0.7
26
-
27
- guard var data = UIImageJPEGRepresentation(image, quality) else {
28
-
29
- return nil
30
-
31
- }
32
-
33
-
34
-
35
- while data.count > maxBytes {
36
-
37
- quality *= min(0.7, CGFloat(maxBytes) / CGFloat(data.count))
38
-
39
- guard let newData = UIImageJPEGRepresentation(image, quality) else {
40
-
41
- return nil
42
-
43
- }
44
-
45
-
46
-
47
- if data.count == newData.count && quality != 0 {
48
-
49
- quality = 0
50
-
51
- }
52
-
53
-
54
-
55
- data = newData
56
-
57
-
58
-
59
- if quality == 0 {
60
-
61
- break
62
-
63
- }
64
-
65
- }
66
-
67
-
68
-
69
- return data
70
-
71
- }
72
-
73
- ```