Commit 3cd86481 by Sarkizz

把图片写入操作放到异步

parent 392a855d
......@@ -36,6 +36,36 @@ extension UIImage {
if !FileManager.default.fileExists(atPath: url.absoluteString) {
do {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
var q: CGFloat = 1
var thumbPath: URL?
switch config {
case .custom(let size, let quality):
q = quality
if let thumbImage = self.thumbImage(size) {
thumbPath = url.appendingPathComponent(self.thumbName(with: name, size: thumbImage.size))
let error = thumbImage.writeFile(to: thumbPath!, q)
if error != nil {
DispatchQueue.main.async {
complate?(nil, nil, error)
}
return
}
}
break
default:
break
}
let fullPath = url.appendingPathComponent(name)
let error = self.writeFile(to: fullPath, q)
DispatchQueue.main.async {
if let error = error {
complate?(nil, nil, error)
} else {
complate?(fullPath, thumbPath, nil)
}
}
} catch let error {
DispatchQueue.main.async {
complate?(nil, nil, error)
......@@ -43,36 +73,6 @@ extension UIImage {
return
}
}
var q: CGFloat = 1
var thumbPath: URL?
switch config {
case .custom(let size, let quality):
q = quality
if let thumbImage = self.thumbImage(size) {
thumbPath = url.appendingPathComponent(self.thumbName(with: name, size: thumbImage.size))
let error = thumbImage.writeFile(to: thumbPath!, q)
if error != nil {
DispatchQueue.main.async {
complate?(nil, nil, error)
}
return
}
}
break
default:
break
}
let fullPath = url.appendingPathComponent(name)
let error = self.writeFile(to: fullPath, q)
DispatchQueue.main.async {
if let error = error {
complate?(nil, nil, error)
} else {
complate?(fullPath, thumbPath, nil)
}
}
}
}
......@@ -113,9 +113,9 @@ extension UIImage {
let wr = size.width / self.size.width
let hr = size.height / self.size.height
if wr > hr {
return CGSize(width: size.width, height: self.size.height * wr)
} else {
return CGSize(width: self.size.width * hr, height: size.height)
} else {
return CGSize(width: size.width, height: self.size.height * wr)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment