GPUImage过滤器链

时间:2015-04-28 08:19:38

标签: ios objective-c gpuimage

我正在尝试使用GPUImage将滤镜应用于图像,但我只是将最后一个滤镜应用于图像。

以下是代码:

UIImage *inputImage = [UIImage imageNamed:@"2.jpg"];
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];

    //Set Brightness to 60
    GPUImageBrightnessFilter *brightnessFilter = [GPUImageBrightnessFilter new];
    [brightnessFilter setBrightness:2];

    //Set Contrast to 12
    GPUImageContrastFilter *contrastFilter = [GPUImageContrastFilter new];
    [contrastFilter setContrast:1.0];

    [contrastFilter addTarget:brightnessFilter];
    [stillImageSource addTarget:contrastFilter];

    [contrastFilter useNextFrameForImageCapture];
    [stillImageSource processImage];

    UIImage *outputImage1 = [contrastFilter imageFromCurrentFramebuffer];
    imageView.image = outputImage1;

1 个答案:

答案 0 :(得分:0)

- (UIImage *)doctorTheImage:(UIImage *)originalImage
{

   const float brownsMask[6] = {85, 255, 85, 255, 85, 255};


    UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];

    UIGraphicsBeginImageContext(originalImage.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBFillColor (context, 1.0,1.0, 1.0, 1);


    CGContextFillRect(context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height));

    CGImageRef brownRef = CGImageCreateWithMaskingColors(imageView.image.CGImage, brownsMask);

    CGRect imageRect = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);

    CGContextTranslateCTM(context, 0, imageView.image.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    //CGImageRef whiteRef = CGImageCreateWithMaskingColors(brownRef, whiteMask);
    CGContextDrawImage (context, imageRect, brownRef);

    //[originalImage drawInRect:CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height)];

    CGImageRelease(brownRef);
   // CGImageRelease(whiteRef);

    UIImage *doctoredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return doctoredImage;
}

您可以尝试使用此代码更改蒙版中定义的特定颜色范围。如果你 想要更多的参考你可以参考这些堆栈溢出链接:How to change the skin color of face from the source image in ios?

相关问题