|
@@ -230,5 +230,26 @@ public extension UIImage {
|
|
|
UIGraphicsEndImageContext()
|
|
|
return tintedImage
|
|
|
}
|
|
|
+
|
|
|
+ /// 保存图片文件到指定目录, 如果目录已经存在会先删除老文件
|
|
|
+ /// - Parameters:
|
|
|
+ /// - currentImage: 图片数据
|
|
|
+ /// - persent: 质量
|
|
|
+ /// - outFilePath: 输出目录
|
|
|
+ class func saveImage(currentImage: UIImage,outFilePath: String) {
|
|
|
+ // 文件存在先删除老文件
|
|
|
+ if FileManager.default.fileExists(atPath: outFilePath) {
|
|
|
+ do {
|
|
|
+ try FileManager.default.removeItem(at: NSURL.fileURL(withPath: outFilePath))
|
|
|
+ } catch {
|
|
|
+ BFLog(message: "删除文件出错 == \(error) \(outFilePath)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if let imageData = currentImage.pngData() {
|
|
|
+ try? imageData.write(to: URL(fileURLWithPath: outFilePath))
|
|
|
+ print("保存图片成功到:filePath=\(outFilePath)")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|