|
@@ -15,7 +15,7 @@ let kmnThumbnailFolder: String = {
|
|
|
public class KMNThumbnail: NSObject {
|
|
|
var thumbnailDocument:CPDFDocument = CPDFDocument()
|
|
|
|
|
|
- typealias KMNThumbnailCompletion = (_ image: NSImage?) -> Void
|
|
|
+ typealias KMNThumbnailCompletion = (_ image: NSImage?,_ page:CPDFPage?) -> Void
|
|
|
|
|
|
var thumbnaiPage:CPDFPage? {
|
|
|
get {
|
|
@@ -99,28 +99,28 @@ public class KMNThumbnail: NSObject {
|
|
|
thumSize.height = pageSize.height * minScanl
|
|
|
}
|
|
|
|
|
|
- thumbnaiPage?.thumbnail(of: thumSize, needReset: true,completion: { pageImage in
|
|
|
+ thumbnaiPage?.thumbnail(of: thumSize, needReset: true,completion: {[weak self] pageImage in
|
|
|
if completion != nil {
|
|
|
- completion!(pageImage)
|
|
|
+ completion!(pageImage,self?.thumbnaiPage)
|
|
|
}
|
|
|
// 将 NSImage 转换为 PNG 数据
|
|
|
guard let tiffData = pageImage?.tiffRepresentation,
|
|
|
- let bitmapImage = NSBitmapImageRep(data: tiffData),
|
|
|
- let pngData = bitmapImage.representation(using: .png, properties: [:]) else {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- do {
|
|
|
- try pngData.write(to: URL(fileURLWithPath: imageFilePath))
|
|
|
- } catch {
|
|
|
- }
|
|
|
+ let bitmapImage = NSBitmapImageRep(data: tiffData),
|
|
|
+ let pngData = bitmapImage.representation(using: .png, properties: [:]) else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ do {
|
|
|
+ try pngData.write(to: URL(fileURLWithPath: imageFilePath))
|
|
|
+ } catch {
|
|
|
+ }
|
|
|
|
|
|
});
|
|
|
} else {
|
|
|
if fileManager.fileExists(atPath: imageFilePath) {
|
|
|
let image = NSImage.init(contentsOfFile: imageFilePath) ?? NSImage()
|
|
|
if completion != nil {
|
|
|
- completion!(image)
|
|
|
+ completion!(image,self.thumbnaiPage)
|
|
|
}
|
|
|
} else {
|
|
|
let maxOrg = max(thumSize.width, thumSize.height)
|
|
@@ -141,9 +141,9 @@ public class KMNThumbnail: NSObject {
|
|
|
thumSize.height = pageSize.height * minScanl
|
|
|
}
|
|
|
|
|
|
- thumbnaiPage?.thumbnail(of: thumSize, needReset: true,completion: { pageImage in
|
|
|
+ thumbnaiPage?.thumbnail(of: thumSize, needReset: true,completion: {[weak self] pageImage in
|
|
|
if completion != nil {
|
|
|
- completion!(pageImage)
|
|
|
+ completion!(pageImage,self?.thumbnaiPage)
|
|
|
}
|
|
|
// 将 NSImage 转换为 PNG 数据
|
|
|
guard let tiffData = pageImage?.tiffRepresentation,
|