spacecash21 spacecash21 - 1 month ago 7
Swift Question

Swift Mac Quick Look get image displayed

Once you open a file with QuickLook, it displays an image.
Is it possible to get the image shown on QLPreviewPanel?
Or maybe open panel and do a screenshot of the Panel's View with the image?

Tried using QLThumbnailImageCreate, but for some reason result is nil. Even though, the "Preview" app generates a correct thumbnail.

Answer Source

According to this: How to put the QLPreviewPanel show as a popover in cocoa?

I created a view in IB. Created a class.

class MAQuickLookItem: NSObject, QLPreviewItem {

var previewItemURL: URL?
var previewItemTitle: String?


and then

    let view = QLPreviewView(frame: NSMakeRect(0, 0, previewView.frame.size.width, previewView.frame.size.height), style: .normal)

    let item = MAQuickLookItem()
    item.previewItemTitle = self.previewFiles?[0].widePath
    item.previewItemURL = URL(fileURLWithPath: (self.previewFiles?[0].widePath)!)

    view?.previewItem = item

Now you can simply do a screenshot of the view.