8

有什么方法可以快速查看文件的预览图像吗?

我正在寻找这样的东西:

NSImage *image = [QuickLookPreviewer quickLookPreviewForFile:path];

4

2 回答 2

6

请参阅QLThumbnailRequest文档:https ://developer.apple.com/library/mac/#documentation/UserExperience/Reference/QLThumbnailRequest_Ref/Reference/reference.html

NSURL *path = aFileUrl;

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kQLThumbnailOptionIconModeKey];

CGImageRef ref = QLThumbnailImageCreate(kCFAllocatorDefault, (CFURLRef)path, CGSizeMake(600, 800 /* Or whatever size you want */), (CFDictionaryRef)options);
于 2012-02-16T08:49:17.933 回答
2

在 Swift 中,我得到了这样的结果(应该替换强制展开):

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))
于 2018-10-21T12:14:49.110 回答