好的,这是我的问题:
NSImageView
子类,用户可以在其上拖动图像(a.k.a。dropper
)NSImageView
旁边(a.k.a。output
)到目前为止非常简单。
问题是,每当我尝试调整窗口大小( 显示已处理的图像后),应用程序崩溃(EXC_BAD_ACCESS
),控制台中没有显示任何内容(没有实际错误,即使NSZombieEnabled
设置为on)。
如果我只是“复制”图像,调整大小可以正常工作:
[_output setImage:[_dropper image]];
但是,当我将_output
的图像设置为过滤后的版本时,会出现问题:
NSImage* processed = [[[_dropper image] copy] filteredWith:[CIFilter sepiaToneWithIntensity:0.5]];
[_output setImage:processed];
以下是上面提到的两个函数(实际上,我分别为CIImage
和CIFilter
编写了类别):
- (NSImage*)filteredWith:(CIFilter *)filter
{
NSImage* start = [self copy];
CIContext* context = [[CIContext alloc] init];
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)[start TIFFRepresentation], NULL);
CGImageRef ref = CGImageSourceCreateImageAtIndex(src, 0, NULL);
CIImage* img = [CIImage imageWithCGImage:ref];
[filter setValue:img forKey:kCIInputImageKey];
CIImage* result = [filter valueForKey:kCIOutputImageKey];
CGImageRef res = [context createCGImage:result fromRect:[result extent]];
NSImage* final = [[NSImage alloc] initWithCGImage:res size:[start size]];
return final;
}
+ (CIFilter*)sepiaToneWithIntensity:(CGFloat)intensity
{
CIFilter* newFilter = [CIFilter filterWithName:@"CISepiaTone"];
[newFilter setValue:[NSNumber numberWithFloat:intensity] forKey:@"inputIntensity"];
return newFilter;
}
有什么想法吗?