代码之家  ›  专栏  ›  技术社区  ›  Evan Layman

新GPUImage无法获取processedImage

  •  0
  • Evan Layman  · 技术社区  · 10 年前

    我对最新的重构有问题。每次我试图从过滤器中获取经过处理的UIImage时,它都是零。我用过 useNextFrameForImageCapture 但它仍然不起作用。 下面是我的代码片段:

    self.imageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0,
                                                0,
                                                self.view.frame.size.width,
                                                self.view.frame.size.height)];
    staticPicture = [[GPUImagePicture alloc] initWithImage:img
                                       smoothlyScaleOutput:YES];
    filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"cool"];
    [staticPicture addTarget:filter];
    [filter addTarget:self.imageView];
    
    GPUImageRotationMode imageViewRotationMode = kGPUImageNoRotation;
    switch (staticPictureOriginalOrientation) {
        case UIImageOrientationLeft:
            imageViewRotationMode = kGPUImageRotateLeft;
            break;
        case UIImageOrientationRight:
            imageViewRotationMode = kGPUImageRotateRight;
            break;
        case UIImageOrientationDown:
            imageViewRotationMode = kGPUImageRotate180;
            break;
        default:
            imageViewRotationMode = kGPUImageNoRotation;
            break;
    }
    
    // seems like atIndex is ignored by GPUImageView...
    [self.imageView setInputRotation:imageViewRotationMode atIndex:0];
    
    [staticPicture useNextFrameForImageCapture];
    [staticPicture processImage];
    UIImage *processedImage = [filter imageFromCurrentFramebufferWithOrientation:staticPictureOriginalOrientation];
    

    processedImage始终为空。非常感谢您的帮助!

    1 回复  |  直到 10 年前
        1
  •  0
  •   Evan Layman    10 年前

    @BradLarson回答了我的问题:您需要在要从中捕获的过滤器上使用-useNextFrameForImageCapture,而不是输入图像。它必须告诉过滤器保留其帧缓冲区。在这种情况下,您需要调用[filter useNextFrameForImageCapture]。