iOS - GPUImage distorted

422 Views Asked by At

I am using GPUImage to apply live filters on camera views. the problem is once I capture an image, it gets pixelated Here is my code:

in 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];

And this is how I am capturing the image:

[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
    }
}];

I added break points to track the execution and see in which part exactly the image gets pixelated. It was the GPUImageOutput 's imageFromCurrentFramebufferWithOrientation: at this line:

CGImageRef cgImageFromBytes = [self newCGImageFromCurrentlyProcessedOutput];

newCGImageFromCurrentlyProcessedOutput always returns nil

- (CGImageRef)newCGImageFromCurrentlyProcessedOutput;
{
    return nil;
}

How can I fix this?

0

There are 0 best solutions below