ProcessThumbnal.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // ProcessThumbnal.swift
  3. // ProcessCheckFile
  4. //
  5. // Created by 朱东勇 on 2022/12/9.
  6. //
  7. import Foundation
  8. import QuickLook
  9. import QuickLookUI
  10. import QuickLookThumbnailing
  11. let generator = QLThumbnailGenerator.shared
  12. class ProcessThumbnal : NSObject {
  13. class func process(_ filePath:String) {
  14. let url = URL.init(filePath: filePath)
  15. generator.generateRepresentations(for: QLThumbnailGenerator.Request.init(fileAt: url, size: CGSizeMake(1024.0, 10240.0), scale: 1.0, representationTypes: QLThumbnailGenerator.Request.RepresentationTypes.thumbnail),
  16. update: { (representation, type, error) in
  17. let image = representation!.nsImage as NSImage
  18. try? image.tiffRepresentation?.write(to: URL.init(filePath: "/Users/zhudongyong/Desktop/imae01.png"))
  19. NSLog("\(representation?.nsImage)\(error)")
  20. })
  21. generator.generateRepresentations(for: QLThumbnailGenerator.Request.init(fileAt: url, size: CGSizeMake(1024.0, 10240.0), scale: 1.0, representationTypes: QLThumbnailGenerator.Request.RepresentationTypes.thumbnail),
  22. update: { (representation, type, error) in
  23. let image = representation!.nsImage as NSImage
  24. try? image.tiffRepresentation?.write(to: URL.init(filePath: "/Users/zhudongyong/Desktop/imae02.png"))
  25. NSLog("\(representation?.nsImage)\(error)")
  26. })
  27. // return []
  28. }
  29. }