Objective c 应用程序包中的ImageMagick
我发现女巫和我的问题很相似。中的代码看起来是我一直在寻找的东西:Objective c 应用程序包中的ImageMagick,objective-c,xcode,macos,cocoa,Objective C,Xcode,Macos,Cocoa,我发现女巫和我的问题很相似。中的代码看起来是我一直在寻找的东西: -(id)init { if ([super init]) { NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; NSString* imageMagickPath = [bundlePath stringByAppendingPathComponent:@"/Contents/Resources/ImageMagi
-(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'
如何修复它?要使用链接的代码,可能只需要将它们声明为全局变量
NSString * MAGICK_HOME = nil;
NSString * DYLD_LIBRARY_PATH = nil;
@implementation ...
将助手
替换为[self class]
,并从链接源添加功能:
/*
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;
}
/*
NSFileManager:获取用户库目录中的路径
原始资料来源:
(见版权公告,网址为)
*/
/*返回给定子路径的用户库路径中的路径。换句话说,如果给定inSubPath为“foo”,则返回的路径将为/Users/myUser/library/foo
"*/
-(NSString*)路径FromUserLibraryPath:(NSString*)inSubPath
{
NSArray*domains=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,是);
NSString*baseDir=[domains objectAtIndex:0];
NSString*result=[baseDir stringByAppendingPathComponent:inSubPath];
返回结果;
}
要使用链接的代码,您可能只需要将它们声明为全局变量
NSString * MAGICK_HOME = nil;
NSString * DYLD_LIBRARY_PATH = nil;
@implementation ...
将助手
替换为[self class]
,并从链接源添加功能:
/*
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;
}
/*
NSFileManager:获取用户库目录中的路径
原始资料来源:
(见版权公告,网址为)
*/
/*返回给定子路径的用户库路径中的路径。换句话说,如果给定inSubPath为“foo”,则返回的路径将为/Users/myUser/library/foo
"*/
-(NSString*)路径FromUserLibraryPath:(NSString*)inSubPath
{
NSArray*domains=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,是);
NSString*baseDir=[domains objectAtIndex:0];
NSString*result=[baseDir stringByAppendingPathComponent:inSubPath];
返回结果;
}