2

我正在使用 GPUImage 在相机视图上应用实时过滤器。问题是一旦我捕获图像,它就会被像素化这是我的代码:

在 viewDidLoad 中:

imageCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
imageCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
normalImgView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height-100)];
[normalImgView setFillMode:kGPUImageFillModePreserveAspectRatioAndFill];

这就是我捕获图像的方式:

[imageCamera capturePhotoAsImageProcessedUpToFilter:selectedFilter withCompletionHandler:^(UIImage *processedImage, NSError *error){
    NSLog(@"processedImage %@", processedImage);

    NSData *dataForPNGFile = UIImageJPEGRepresentation(processedImage, 1.0);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSError *error2 = nil;
    if (![dataForPNGFile writeToFile:[documentsDirectory stringByAppendingPathComponent:@"FilteredPhoto.jpg"] options:NSAtomicWrite error:&error2])
    {
        return;
    }

    if (processedImage) {
        //Display it in an image view
    }
}];

我添加了断点来跟踪执行情况,并查看图像在哪一部分被像素化。这是 GPUImageOutput 的 imageFromCurrentFramebufferWithOrientation: 在这一行:

CGImageRef cgImageFromBytes = [self newCGImageFromCurrentlyProcessedOutput];

newCGImageFromCurrentlyProcessedOutput 总是返回 nil

- (CGImageRef)newCGImageFromCurrentlyProcessedOutput;
{
    return nil;
}

我怎样才能解决这个问题?

4

0 回答 0