forked from pro648/BasicDemos-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIKit.swift
More file actions
28 lines (24 loc) · 735 Bytes
/
Copy pathUIKit.swift
File metadata and controls
28 lines (24 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// UIKit.swift
// ImageResizing
//
// Created by ad on 2022/1/15.
//
import UIKit
enum UIKit {
static func resizedImage(at url: URL, for size: CGSize) -> UIImage? {
guard let image = UIImage(contentsOfFile: url.path) else { return nil }
var format: UIGraphicsImageRendererFormat
if #available(iOS 11.0, *) {
format = .preferred()
} else {
format = .default()
}
format.opaque = false
format.scale = UIScreen.main.scale
let renderer = UIGraphicsImageRenderer(size: size, format: format)
return renderer.image { context in
image.draw(in: CGRect(origin: .zero, size: size))
}
}
}