Mac快速查看预览在NSView或NSImage? [英] Mac Quick Look Preview in an NSView or NSImage?

查看:591
本文介绍了Mac快速查看预览在NSView或NSImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式(公共或其他方式)来获取NSView,NSImage,CGImageRef等显示文件的 QuickLook预览。基本上相当于QLThumbnailImageCreate(),但是预览。

I am looking for a way (public or otherwise) to get an NSView, NSImage, CGImageRef, etc that shows the QuickLook preview for a file. Essentially the equivalent of QLThumbnailImageCreate() but for the preview.

我可以找到的公共API不支持这个。它们允许创建缩略图图像或QLPreviewPanel。该面板实际上显示快速预览,但我无法访问预览的外观来嵌入其他视图,也不能一次显示多个预览。

The public APIs I can find do not support this. They allow the creation of a thumbnail image or a QLPreviewPanel. The panel does in fact display the quick look preview, but I cannot get access to the preview's appearance to embed it in other views, nor can I display multiple previews at once.

对于背景,我写一个应用程序,用户可以嵌入链接到其他文件,应该显示内联,种类像< img>标记。对于像JPG和PDF这样的图片,很容易找出要显示的内容。我认为对于其他格式,我会使用快速查看生成文件的内容的一个很好的视觉表示。这样,我的应用程序支持的一组格式将很容易扩展(只需下载新的Quick Look生成器)。

For background, I am writing an app where users can embed links to other files that should be displayed inline, kind of like an <img> tag in HTML. For images like JPGs and PDFs it's easy to figure out what to display. I thought that for other formats I would use Quick Look to generate a nice visual representation of the file's contents. This way the set of formats supported by my application would be easily extensible (just download new Quick Look generators).

推荐答案

进入这个广泛地一次一次,并且不能找到一个简单的方法做到。根据文件的类型,QuickLook生成不同类型的输出。例如,对于iWork文件,生成器会生成在WebView中显示的HTML。对于其他类型,它返回不同类型的数据。

I looked into this extensively once a while back and was not able to find an easy way to do it. Depending on the type of file, QuickLook generates different kinds of output. For example, for iWork files, the generator makes HTML that it displays in a WebView. For other types it returns different types of data.

我从来没有使用过代码,但这里有一些代码我挖出来和一些私人API可能方便: / p>

I never ended up using the code, but here's some code I dug up and some private APIs that might be handy:

id QLPreviewCreate(CFAllocatorRef allocator, CFURLRef url,  CFDictionaryRef options);
id QLPreviewCopyBitmapImage(id preview);
id QLPreviewCopyData(id preview);
NSString* QLPreviewGetPreviewType(id preview);
id QLPreviewCopyProperties(id preview);

- (NSData *)getDataForFile:(NSString *)path
{

    NSURL *fileURL = [NSURL fileURLWithPath:path];

    id preview = QLPreviewCreate(kCFAllocatorDefault, fileURL, 0);

    if (preview)
    {
        NSString* previewType = QLPreviewGetPreviewType(preview);

        if ([previewType isEqualToString:@"public.webcontent"])
        {
            // this preview is HTML data
            return QLPreviewCopyData(preview);
        }
        else
        {
           NSLog(@"this type is: %@", previewType);
           // do something else
        }

    }

    return nil;
}

这篇关于Mac快速查看预览在NSView或NSImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆