Get QuickLook preview image for file

前端 未结 2 1049
我寻月下人不归
我寻月下人不归 2020-12-31 17:41

Is there any way to get the quick look preview image for a file?

I\'m looking for something like this:

NSImage *image = [QuickLookPreviewer quickLookPr

2条回答
  •  长情又很酷
    2020-12-31 18:17

    In Swift I ended up with something like this (the force unwraps should be replaced):

    let options = [
      kQLThumbnailOptionIconModeKey: false
    ]
    
    let ref = QLThumbnailCreate(
      kCFAllocatorDefault,
      url as NSURL,
      CGSize(width: 150, height: 150),
      options as CFDictionary
    )
    
    let thumbnail = ref!.takeRetainedValue()
    let cgImageRef = QLThumbnailCopyImage(thumbnail)
    let cgImage = cgImageRef!.takeRetainedValue()
    let image = NSImage(cgImage: cgImage, size: CGSize(width: cgImage.width, height: cgImage.height))
    

提交回复
热议问题