質問編集履歴

7

やり直し

2019/04/19 06:51

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -69,63 +69,3 @@
69
69
  初期状態
70
70
 
71
71
  ![スクリーンショット](861f63b31c7b2d99f35ce8aa3164bee7.png)
72
-
73
-
74
-
75
- resizeを変更後
76
-
77
- ![スクリーンショット2](74e81d7a45cf6254554d7b4e4f211a4d.png)
78
-
79
-
80
-
81
- ↑このコード
82
-
83
- ```swift
84
-
85
- extension UIImage {
86
-
87
- func resize2(_size: CGSize) -> UIImage {
88
-
89
- print(_size.width.description+"x"+_size.height.description)
90
-
91
- let widthRatio = _size.width / self.size.width
92
-
93
- let heightRatio = _size.height / self.size.height
94
-
95
- let ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio
96
-
97
- let resizedSize = CGSize(width: (self.size.width * ratio), height: (self.size.height * ratio))
98
-
99
- // 画質を落とさないように以下を修正
100
-
101
- // UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)
102
-
103
- // draw(in: CGRect(x: 0, y: 0, width: resizedSize.width, height: resizedSize.height))
104
-
105
- UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
106
-
107
- draw(in: CGRect(x: (size.width - resizedSize.width) / 2, y: (size.height - resizedSize.height) / 2, width: resizedSize.width, height: resizedSize.height))
108
-
109
- let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
110
-
111
- UIGraphicsEndImageContext()
112
-
113
- return resizedImage ?? self;
114
-
115
- }
116
-
117
- }
118
-
119
- ```
120
-
121
-
122
-
123
- 呼び出し元
124
-
125
- ```swift
126
-
127
- cell.imageView?.image = image.resize2(_size: CGSize(width:400,height:200))
128
-
129
-
130
-
131
- ```

6

試したコードを追記

2019/04/19 06:51

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -75,3 +75,57 @@
75
75
  resizeを変更後
76
76
 
77
77
  ![スクリーンショット2](74e81d7a45cf6254554d7b4e4f211a4d.png)
78
+
79
+
80
+
81
+ ↑このコード
82
+
83
+ ```swift
84
+
85
+ extension UIImage {
86
+
87
+ func resize2(_size: CGSize) -> UIImage {
88
+
89
+ print(_size.width.description+"x"+_size.height.description)
90
+
91
+ let widthRatio = _size.width / self.size.width
92
+
93
+ let heightRatio = _size.height / self.size.height
94
+
95
+ let ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio
96
+
97
+ let resizedSize = CGSize(width: (self.size.width * ratio), height: (self.size.height * ratio))
98
+
99
+ // 画質を落とさないように以下を修正
100
+
101
+ // UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)
102
+
103
+ // draw(in: CGRect(x: 0, y: 0, width: resizedSize.width, height: resizedSize.height))
104
+
105
+ UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
106
+
107
+ draw(in: CGRect(x: (size.width - resizedSize.width) / 2, y: (size.height - resizedSize.height) / 2, width: resizedSize.width, height: resizedSize.height))
108
+
109
+ let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
110
+
111
+ UIGraphicsEndImageContext()
112
+
113
+ return resizedImage ?? self;
114
+
115
+ }
116
+
117
+ }
118
+
119
+ ```
120
+
121
+
122
+
123
+ 呼び出し元
124
+
125
+ ```swift
126
+
127
+ cell.imageView?.image = image.resize2(_size: CGSize(width:400,height:200))
128
+
129
+
130
+
131
+ ```

5

resize変更後のスクリーンショット追加

2019/04/19 06:13

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -66,56 +66,12 @@
66
66
 
67
67
 
68
68
 
69
+ 初期状態
70
+
69
71
  ![スクリーンショット](861f63b31c7b2d99f35ce8aa3164bee7.png)
70
72
 
71
73
 
72
74
 
73
- 恐れ入ります。
75
+ resizeを変更後
74
76
 
75
- swiftの基本的なことなのかもしれませんが
76
-
77
- extension UIImageのresizeに入ってきていないようです。
78
-
79
-
80
-
81
- 以下のコードを呼び出し元のクラスモジュールと同じファイルに記述しているのですが、
82
-
83
- 引数をsizeから_sizeに変更したのに、呼び出し元でエラーになりません。
84
-
85
- もしかしてswift4になって、UIImageにresizeメソッドが追加されたのでしょうか。
86
-
87
-
88
-
89
- ```swift
90
-
91
- extension UIImage {
92
-
93
-
94
-
95
- func resize(_size: CGSize) -> UIImage {
96
-
97
- print(_size.width.description+"x"+_size.height.description)
98
-
99
- let widthRatio = _size.width / self.size.width
77
+ ![スクリーンショット2](74e81d7a45cf6254554d7b4e4f211a4d.png)
100
-
101
- let heightRatio = _size.height / self.size.height
102
-
103
- let ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio
104
-
105
- let resizedSize = CGSize(width: (self.size.width * ratio), height: (self.size.height * ratio))
106
-
107
-
108
-
109
- UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)
110
-
111
- draw(in: CGRect(x: 0, y: 0, width: resizedSize.width, height: resizedSize.height))
112
-
113
- UIGraphicsEndImageContext()
114
-
115
- return resizedImage ?? self;
116
-
117
- }
118
-
119
- }
120
-
121
- ```

4

resizeについての追記

2019/04/19 05:53

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -67,3 +67,55 @@
67
67
 
68
68
 
69
69
  ![スクリーンショット](861f63b31c7b2d99f35ce8aa3164bee7.png)
70
+
71
+
72
+
73
+ 恐れ入ります。
74
+
75
+ swiftの基本的なことなのかもしれませんが
76
+
77
+ extension UIImageのresizeに入ってきていないようです。
78
+
79
+
80
+
81
+ 以下のコードを呼び出し元のクラスモジュールと同じファイルに記述しているのですが、
82
+
83
+ 引数をsizeから_sizeに変更したのに、呼び出し元でエラーになりません。
84
+
85
+ もしかしてswift4になって、UIImageにresizeメソッドが追加されたのでしょうか。
86
+
87
+
88
+
89
+ ```swift
90
+
91
+ extension UIImage {
92
+
93
+
94
+
95
+ func resize(_size: CGSize) -> UIImage {
96
+
97
+ print(_size.width.description+"x"+_size.height.description)
98
+
99
+ let widthRatio = _size.width / self.size.width
100
+
101
+ let heightRatio = _size.height / self.size.height
102
+
103
+ let ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio
104
+
105
+ let resizedSize = CGSize(width: (self.size.width * ratio), height: (self.size.height * ratio))
106
+
107
+
108
+
109
+ UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)
110
+
111
+ draw(in: CGRect(x: 0, y: 0, width: resizedSize.width, height: resizedSize.height))
112
+
113
+ UIGraphicsEndImageContext()
114
+
115
+ return resizedImage ?? self;
116
+
117
+ }
118
+
119
+ }
120
+
121
+ ```

3

スクリーンショット置き換え

2019/04/19 04:39

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -64,4 +64,6 @@
64
64
 
65
65
  どうすればよいのでしょうか。
66
66
 
67
+
68
+
67
- ![スクリーンショット](428350e94ac99b9a2f037c89e3960c8a.png)
69
+ ![スクリーンショット](861f63b31c7b2d99f35ce8aa3164bee7.png)

2

スクリーンショット置き換え

2019/04/19 02:26

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,4 @@
64
64
 
65
65
  どうすればよいのでしょうか。
66
66
 
67
-
68
-
69
- ![スクリンショット](5e3ed5c2497b644b634ce287552b07b8.png)
67
+ ![スクリンショット](428350e94ac99b9a2f037c89e3960c8a.png)

1

スクリーンショットを追加

2019/04/19 02:20

投稿

SakuTaka
SakuTaka

スコア12

test CHANGED
File without changes
test CHANGED
@@ -63,3 +63,7 @@
63
63
 
64
64
 
65
65
  どうすればよいのでしょうか。
66
+
67
+
68
+
69
+ ![スクリンショット](5e3ed5c2497b644b634ce287552b07b8.png)