0

When I use iconForFile: in NSWorkSpace class, I get the default Mac image file icon.

However, I would like to get the actual image that are previewed on the desktop.
How can I go about this?

Matthias
  • 3,582
  • 2
  • 30
  • 41
wayfare
  • 699
  • 2
  • 9
  • 17

2 Answers2

4

[[NSImage alloc] initWithContentsOfFile:filename]

Jay
  • 6,572
  • 3
  • 37
  • 65
Wil Shipley
  • 9,343
  • 35
  • 59
1

If you want the contents of the image file, use [[NSImage alloc] initWithContentsOfFile:filename] as in Wil's answer.

If you want the way the image file appears in the Finder — a preview of the image file's contents formatted as an icon — you'll need to talk to the QuickLook framework. Call QLThumbnailImageCreate and pass an options dictionary containing YES for the kQLThumbnailOptionIconModeKey key.

rickster
  • 124,678
  • 26
  • 272
  • 326
  • This works very well! However, it is not showing previews for folders. I plan on using '''iconForFile''' from NSWorkSpace class but I was wondering if this could be achieved using QLThumbnailRequest. – wayfare Apr 03 '14 at 03:44