My QuickLook plugin generates HMTL preview for the document. I need to display images saved in the plugin bundle. Simply using imageNamed:
method to get an instance of the NSImage
class doesn't work. How can achieve that? Is that a consequence of the fact that
Quick Look generators are designed as CFPlugIn-style bundles.
as the documentation says?
QuickLook looks for and uses the plugins from both system-wide folders '/System/Library/QuickLook' and '/Library/QuickLook' and also the home folder of each user in '~/Library/QuickLook'. A QuickLook plugin is organised in a folder with an extension .
Click any file, and hit the spacebar. You'll instantly see a preview of it. You can use the arrow keys to jump between files—the preview will immediately load. Here are the file types you can see with QuickLook.
To install QuickLook plugins, you should copy the “*. qlgenerator” file into /Library/QuickLook/ or ~/Library/QuickLook/. Note that “*” in the filename will vary based on exactly which QuickLook item you choose to install. If a QuickLook folder is not present, feel free to create one.
Quick Look offers a fast, full-size preview of nearly any kind of file without opening the file. You can rotate photos, trim audio and video clips, and use Markup—directly in the Quick Look window.
I believe +imageNamed: uses the +mainBundle method of NSBundle. In that case, that's not your plugin's bundle.
I think you'll need to ask the plugin's bundle directly:
NSString * path = [[[NSBundle bundleForClass:[MyPluginClass class]] pathForResource:@"MyImage" ofType:@"tif"];
NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
This was written in the browser, so it may not be exact. :-)
Within the plug-in code, you can access your plug-in CFBundle:
QLThumbnailRequestGetGeneratorBundle or QLPreviewRequestGetGeneratorBundle
Once you have the bundle, you can query for resources file URLs using:
CFBundleCopyResourceURL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With