Commit a33c0e4a by Sarkizz

修正压缩图片逻辑

parent 634a14d2
...@@ -13,9 +13,9 @@ import Photos ...@@ -13,9 +13,9 @@ import Photos
public typealias UIImageSaveToAlbumCompleteBlock = (_ image: UIImage, _ saveURL: URL?, _ error: Error?) -> Void public typealias UIImageSaveToAlbumCompleteBlock = (_ image: UIImage, _ saveURL: URL?, _ error: Error?) -> Void
extension UIImage { extension UIImage {
public enum SaveConfig { public enum SaveConfig: Equatable {
case `default` case `default`
case custom(_ thumbSize: CGSize?, _ quality: CGFloat) case custom(_ thumbSize: CGSize, _ quality: CGFloat)
} }
} }
...@@ -49,7 +49,7 @@ extension UIImage { ...@@ -49,7 +49,7 @@ extension UIImage {
switch config { switch config {
case .custom(let size, let quality): case .custom(let size, let quality):
q = quality q = quality
if let size = size, let thumbImage = self.thumbImage(size) { if let thumbImage = self.thumbImage(size) {
thumbPath = url.appendingPathComponent(self.thumbName(with: name, size: thumbImage.size)) thumbPath = url.appendingPathComponent(self.thumbName(with: name, size: thumbImage.size))
let error = thumbImage.writeFile(to: thumbPath!, q) let error = thumbImage.writeFile(to: thumbPath!, q)
if error != nil { if error != nil {
...@@ -65,14 +65,12 @@ extension UIImage { ...@@ -65,14 +65,12 @@ extension UIImage {
} }
let fullPath = url.appendingPathComponent(name) let fullPath = url.appendingPathComponent(name)
do { let error = self.writeFile(to: fullPath, q)
try self.jpegData(compressionQuality: q)?.write(to: fullPath)
DispatchQueue.main.async {
complate?(fullPath, thumbPath, nil)
}
} catch let error {
DispatchQueue.main.async { DispatchQueue.main.async {
if let error = error {
complate?(nil, nil, error) complate?(nil, nil, error)
} else {
complate?(fullPath, thumbPath, nil)
} }
} }
} }
......
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