Core Image和Window Resizing的奇怪问题

时间:2013-06-05 07:19:46

标签: objective-c cocoa exc-bad-access core-image

好的,这是我的问题:

  • 我有一个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];

以下是上面提到的两个函数(实际上,我分别为CIImageCIFilter编写了类别):

- (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;
}

有什么想法吗?

0 个答案:

没有答案