简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM