Re: Getting image info without loading entire image
Re: Getting image info without loading entire image
- Subject: Re: Getting image info without loading entire image
- From: Kaelin Colclasure <email@hidden>
- Date: Fri, 19 Jan 2007 10:56:53 -0800
Hi Ken,
I missed the earlier messages in this thread, but... is there a
reason why you're trying to load and run the importer instead of
simply asking Spotlight for the attributes directly?
MDItemRef item = MDItemCreate(kCFAllocatorDefault, inPath);
if (item != NULL) {
CFArrayRef attributeNames = MDItemCopyAttributeNames(item);
CFDictionaryRef attributes = MDItemCopyAttributes(item,
attributeNames);
// ...
}
HTH,
-- Kaelin
On Jan 19, 2007, at 10:18 AM, Ken Tozier wrote:
On Jan 19, 2007, at 7:07 AM, Gregory Weston wrote:
One line of code to load the bundle, and 1 line each to find the
function pointer for the exports. There's also a function that'll
look up the pointers for multiple exports if you like, but the
setup involved is more than it's worth for only 2 functions known
at build-time.
Well thanks again for your help Gregory, but I don't see any way to
reduce section 3 of:
http://developer.apple.com/documentation/Cocoa/Conceptual/
LoadingCode/Tasks/LoadingBundles.html#//apple_ref/doc/uid/
20001273-99770
or anything in this:
http://developer.apple.com/documentation/CoreFoundation/Conceptual/
CFPlugIns/Tasks/loading.html
To 3 lines (or anywhere in the ballpark of 3 lines) of code.
Following the example at the first link yields
typedef Boolean (*GET_METADATA_FOR_FILE)(void *thisInterface,
CFMutableDictionaryRef attributes,
CFStringRef contentTypeUTI,
CFStringRef pathToFile);
NSURL *bundleURL = [NSURL fileURLWithPath: @"/System/Library/
Spotlight/Image.mdimporter"];
NSMutableDictionary * result = [NSMutableDictionary dictionary];
NSString *imagePath = @"path/to/some/image.jpg";
bundleRef = CFBundleCreate(kCFAllocatorDefault, (CFURLRef) bundleURL);
GET_METADATA_FOR_FILE getter = CFBundleGetFunctionPointerForName
(bundleRef, CFSTR("GetMetadataForFile"));
if (getter(bundleRef, (CFMutableDictionaryRef) result,
(CFStringRef) utiType, (CFStringRef) imagePath)))
NSLog(@ result = %@", result );
This crashes the app because apparently there is no function in
Image.mdimporter called "GetMetadataForFile"
Trying to adapt code from the second link yielded:
NSURL *bundleURL = [NSURL fileURLWithPath: @"/System/Library/
Spotlight/Image.mdimporter"];
// uuid strings copied from info.plist file of Image. mdimporter
CFUUIDRef factoryUUID = CFUUIDCreateFromString
(kCFAllocatorDefault, CFSTR("0E74121F-9D55-11D8-9802-000A959816E2")),
typeUUID = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR
("8B08C4BF-415B-11D8-B3F9-0003936726FC"));
bundleRef = CFBundleCreate(kCFAllocatorDefault, (CFURLRef) bundleURL);
plugin = CFPlugInCreate(NULL, (CFURLRef) bundleURL);
importer = CFPlugInInstanceCreate(kCFAllocatorDefault,
factoryUUID, typeUUID);
NSMutableDictionary *result = [NSMutableDictionary dictionary];
NSString *ext = [inPath pathExtension],
*utiType;
utiType = (NSString *) UTTypeCreatePreferredIdentifierForTag
(kUTTagClassFilenameExtension, (CFStringRef) ext, CFSTR
("public.data"));
NSLog(@"utiType = %@", utiType);
if (!getter)
getter = CFBundleGetFunctionPointerForName(importer, CFSTR
("GetMetadataForFile"));
if (!getter)
NSLog(@"GetMetadataForFile could not be found");
else if (getter(bundleRef, (CFMutableDictionaryRef) result,
(CFStringRef) utiType, (CFStringRef) inPath))
return result;
Doesn't work either for the same reason. The rest of the code at
the second link is so obtuse that I don't have time to try and
understand it right now. Back to the old dog slow NSImage solution
I guess...
Thanks again for at least pointing out the Spotlight Metadata
possibility. I may revisit it when I get some breathing room.
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden