【问题标题】:GPUImage filter chainGPUImage滤镜链
【发布时间】:2015-04-28 08:19:37
【问题描述】:

我正在尝试使用 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;

【问题讨论】:

    标签: ios objective-c gpuimage


    【解决方案1】:
    - (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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多