【发布时间】:2012-05-08 12:02:48
【问题描述】:
Apple 是否声明了我不知道的方法 [CIImage initWithImage:(CIImage*)]?我知道的唯一具有该签名的方法是[CISampler initWithImage:]。但是当我尝试提供自己的方法时,编译器会警告我说该方法已经存在。
背景:我正在尝试创建一种将NSImage 实例转换为CIImage 的便捷方法。然后我创建了一个类别方法[CIImage initWithImage:],它接收一个NSImage 实例。
这里是分类方法声明:
@interface CIImage (QuartzCoreExtras)
-(id) initWithImage:(NSImage*) img;
@end
我尝试在 NSImageView 子类中使用它来缓存图像的 CoreImage 版本:
-(void) setImage:(NSImage *)newImage {
[super setImage:newImage];
[ciImage release];
ciImage = [[CIImage alloc] initWithImage:newImage];
}
但是当我编译上面的方法时,我得到一个警告说其他人已经定义了这个方法并且它需要一个不同的参数:
warning: incompatible Objective-C types 'struct NSImage *', expected 'struct CIImage *' when passing argument 1 of 'initWithImage:' from distinct Objective-C type
从 XCode 中的“跳转到定义”选项中,该方法的唯一其他实现(除了我自己的实现)是 [CISampler initWithImage:(CIImage*]。我真的对这个问题感到困惑——我做错了什么吗?
为了完整起见,这里是 [CIImage initWithImage:] 的方法体:
@implementation CIImage (QuartzCoreExtras)
-(id) initWithImage:(NSImage*) img {
NSData* tiffData = [img TIFFRepresentation];
NSBitmapImageRep* bitmap = [NSBitmapImageRep imageRepWithData:tiffData];
return [self initWithBitmapImageRep:bitmap];
}
@end
提前致谢。
【问题讨论】:
标签: cocoa core-image