如何使用静态图像源获取GPUImage动画?

时间:2013-07-28 17:43:13

标签: ios image-processing gpuimage

我试图在UIViewControler中设置一个简单的GPUImage环境。但是,我得到一个空白的屏幕。我希望动画旋转滤波器的属性,同时源图像保持不变。我怎么能这样做?

我想要对大型图像有良好的性能(> 30 fps),因此理想情况下要避免从GPU到CPU的不必要的像素副本。

- (void)viewDidLoad
{
    UIImage *inputImage = [UIImage imageNamed:@"image.jpg"];

    self.stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
    self.swirlFilter = [[GPUImageSwirlFilter alloc] init];
    self.swirlFilter.radius = 0.8;

    self.filteredImageView =
    [[GPUImageView alloc] initWithFrame:
        CGRectMake(0.0, 0.0,
                   self.view.frame.size.width,
                   self.view.frame.size.height)];

    [self.view addSubview:self.filteredImageView];

    // GPUImagePicture -> GPUImageFilter -> GPUImageView
    [self.stillImageSource addTarget:self.swirlFilter];
    [self.swirlFilter addTarget:self.filteredImageView];

    NSAssert(inputImage && _stillImageSource && _swirlFilter && _filteredImageView,
             @"Something unexpected is nil");
}

// Set up a the display link in View Did appear     

- (void) displayLinkDidFire:(CADisplayLink*)displayLink
{
    CGFloat proportion =
    [RSHelper proportionForTime:[[NSDate date] timeIntervalSinceReferenceDate]];

    self.swirlFilter.angle = proportion;

    // Do I need to call some kind of update call here?
}

1 个答案:

答案 0 :(得分:1)

好的,我找到了答案 - 我在processImage

上错过了对GPUImagePicture的来电
- (void) displayLinkDidFire:(CADisplayLink*)displayLink
{
    self.swirlFilter.angle = [Helper calcProportion];
    [self.stillImageSource processImage];
}

GPUImage实际上非常适合设置,并且它的接缝速度比GPUImage docs中所述的CoreImage更快。使用第三方lib而不是苹果的技术让我感到很痛苦,但我没有看到任何优势或CoreImage。