Created
April 19, 2014 19:06
-
-
Save tanb/11094235 to your computer and use it in GitHub Desktop.
FileThumbnail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *fileURLs = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:self.url | |
includingPropertiesForKeys:[NSArray array] | |
options:0 | |
error:nil]; | |
[fileURLs enumerateObjectsUsingBlock:^(NSURL *fileURL , NSUInteger idx, BOOL *stop) { | |
NSImage *elementIcon = [[NSWorkspace sharedWorkspace] iconForFile:[fileURL path]]; | |
CFStringRef fileExtension = (__bridge CFStringRef)[fileURL pathExtension]; | |
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL); | |
if (UTTypeConformsTo(fileUTI, kUTTypeImage)) { | |
// needs QuickLook.framework #import <QuickLook/QuickLook.h> | |
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] | |
forKey:(NSString *)kQLThumbnailOptionIconModeKey]; | |
CGImageRef ref = QLThumbnailImageCreate(kCFAllocatorDefault, (__bridge CFURLRef)fileURL, | |
CGSizeMake(50, 50), (__bridge CFDictionaryRef)options); | |
elementIcon = [[NSImage alloc] initWithCGImage:ref size:CGSizeMake(50, 50)]; | |
} | |
CFRelease(fileUTI); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment