سؤال

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?

هل كانت مفيدة؟

المحلول

[[NSImage alloc] initWithContentsOfFile:filename]

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top