Thursday, July 19, 2018

#1 2011-03-23 10:44:42 am

RIRedinPA
Member
From:: Philadelphia
Registered: 2003-11-12
Posts: 237
Website

Cocoa question: NSURL and Core Graphics to get metadata...

I know this isn't exactly the place to post this question but I've been banging my head all morning to no avail. I'm trying to get the metadata of an image file (tif or eps) but I keep getting null for the dictionary that should hold that data.

- (void)tableViewSelectionDidChange:(NSNotification *)notif {
   
    NSDictionary* metadata = [[NSDictionary alloc] init];
   
    //get selected item
    NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]];
   
    //set path to file selected
    NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData];
   
    //declare a file manager
    NSFileManager* fileManager = [[NSFileManager alloc] init];
   
    //check to see if the file exists
    if ([fileManager fileExistsAtPath:filePath] == YES) {
       
        //escape all the garbage in the string
        NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8);
       
        //convert path to NSURL
        NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString];
       
                //also getting a warning here that NSURL might not accept this method, but its in the docs.
        NSError* error;
        NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]);
           
                        //declare a cg source reference
            CGImageSourceRef  sourceRef;
       
            //set the cg source references to the image by passign its url path
            sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL);
       
            //set a dictionary with the image metadata from the source reference
            metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
       
            NSLog(@"%@", metadata);
       
            [filePathURL release];
       
       
    } else {
       
        [self showAlert:@"I cannot find this file."];
    }
   
    [fileManager release];
   
}


Any help would be appreciated.


Filed under: metadata, cocoa, NSURL

Offline

 

#2 2011-03-23 06:58:18 pm

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2777
Website

Re: Cocoa question: NSURL and Core Graphics to get metadata...

Your problem is simple

you're making an URL an passing it to a method who expects a file path like '/path/to/image.jpg' You can simply do this two ways.

1) if you want to keep the url you can change NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString]; to NSURL* filePathURL = [[NSURL alloc] initWithString:percentEscapedString];

2) if you prefer to use system path you need to delete the percentEscapeString and pass filePath directly to your filePathURL creation

Offline

 

#3 2011-03-24 06:35:56 am

RIRedinPA
Member
From:: Philadelphia
Registered: 2003-11-12
Posts: 237
Website

Re: Cocoa question: NSURL and Core Graphics to get metadata...

Thanks DJ...

That brought some progress as I got these error messages:

Thu Mar 24 09:07:52 ssuranie.merion.com CocoaApp[85650] <Error>: CGImageSourceCreateWithURL failed with error code -15.
Thu Mar 24 09:07:52 ssuranie.merion.com CocoaApp[85650] <Error>: CGImageSourceCopyPropertiesAtIndex image source parameter is nil

Here's the URL I am passing to it:

/Volumes/STORAGE%20SVR/Illustration-Wofford/Illustration%20Pickup/Archive/LTC010109_IL_refinance.eps

Last edited by RIRedinPA (2011-03-24 07:14:41 am)

Offline

 

#4 2011-03-24 07:44:37 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2777
Website

Re: Cocoa question: NSURL and Core Graphics to get metadata...

Sorry, my fault,

The problem remains because the string isn't an url because it doesn't contain the protocol. It takes more than escaping special characters only. What's missing is the protocol of the url so what you need is file:///Volumes/STORAGE%20SVR/Illustration-Wofford/Illustration%20Pickup/Archive/LTC010109_IL_refinance.eps (the three slashes after file: is correct).

Offline

 

#5 2011-03-24 07:48:31 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2777
Website

Re: Cocoa question: NSURL and Core Graphics to get metadata...

Second post but I advise you to do the other way around.

use:

NSURL *filePathURL = [NSURL fileURLWithPath:@"/Volumes/STORAGE SVR/Illustration-Wofford/Illustration Pickup/Archive/LTC010109_IL_refinance.eps" isDirectory:NO];

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)