2012-07-25 45 views
2

我發現question (link)女巫與我的問題非常相似。而在answer代碼看起來要的東西我一直在尋找了很長一段時間:ImageMagick在應用程序包中

-(id)init 
{ 
    if ([super init]) 
    { 
     NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; 
     NSString* imageMagickPath = [bundlePath stringByAppendingPathComponent:@"/Contents/Resources/ImageMagick"]; 
     NSString* imageMagickLibraryPath = [imageMagickPath stringByAppendingPathComponent:@"/lib"]; 

     MAGICK_HOME = imageMagickPath; 
     DYLD_LIBRARY_PATH = imageMagickLibraryPath; 
    } 
    return self; 
} 

-(void)composite 
{ 
    NSTask *task = [[NSTask alloc] init]; 

    // the ImageMagick library needs these two environment variables. 
    NSMutableDictionary* environment = [[NSMutableDictionary alloc] init]; 
    [environment setValue:MAGICK_HOME forKey:@"MAGICK_HOME"]; 
    [environment setValue:DYLD_LIBRARY_PATH forKey:@"DYLD_LIBRARY_PATH"]; 

    // helper function from 
    // http://www.karelia.com/cocoa_legacy/Foundation_Categories/NSFileManager__Get_.m 
    NSString* pwd = [Helpers pathFromUserLibraryPath:@"MyApp"]; 

    // executable binary path 
    NSString* exe = [MAGICK_HOME stringByAppendingPathComponent:@"/bin/composite"]; 

    [task setEnvironment:environment]; 
    [task setCurrentDirectoryPath:pwd]; // pwd 
    [task setLaunchPath:exe]; // the path to composite binary 
    // these are just example arguments 
    [task setArguments:[NSArray arrayWithObjects: @"-gravity", @"center", @"stupid hat.png", @"IDR663.gif", @"bla.png", nil]]; 
    [task launch]; 
    [task waitUntilExit]; 
} 

,但我有6個錯誤,當我嘗試使用它:

Use of undeclared identifier 'MAGICK_HOME' 
Use of undeclared identifier 'DYLD_LIBRARY_PATH' 
Use of undeclared identifier 'MAGICK_HOME' 
Use of undeclared identifier 'DYLD_LIBRARY_PATH' 
Use of undeclared identifier 'Helpers' 
Use of undeclared identifier 'MAGICK_HOME' 

enter image description here

我該如何解決它?

回答

0

要使用你鏈接的代碼,可能你只需要將它們聲明爲全局變量。

NSString * MAGICK_HOME = nil; 
NSString * DYLD_LIBRARY_PATH = nil; 

@implementation ... 

[self class]更換Helpers,並從鏈接源添加的功能:

/* 
    NSFileManager: Get the path within the user's Library directory 
    Original Source: <http://cocoa.karelia.com/Foundation_Categories/NSFileManager__Get_.m> 
    (See copyright notice at <http://cocoa.karelia.com>) 
*/ 

/*" Return the path in the user library path of the given sub-path. In other words, if given inSubPath is "foo", the path returned will be /Users/myUser/Library/foo 
"*/ 
- (NSString *) pathFromUserLibraryPath:(NSString *)inSubPath 
{ 
    NSArray *domains = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES); 
    NSString *baseDir= [domains objectAtIndex:0]; 
    NSString *result = [baseDir stringByAppendingPathComponent:inSubPath]; 
    return result; 
} 
相關問題