spacecash21
spacecash21

Reputation: 1331

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.

Upvotes: 0

Views: 793

Answers (1)

spacecash21
spacecash21

Reputation: 1331

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)
    previewView.addSubview(view!)

    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.

Upvotes: 1

Related Questions