简体   繁体   中英

How to adjust brightness and contrast of CGImageRef

I need to adjust the contrast and brightness of the CGImageRef my means of CoreGraphics/Quartz.

Any ideas how to do it ?

Quartz guildeline and online search didn't give many results.

Please don't refer to OpenGL solution.

You want Core Image . The filter for your purpose is CIColorControls .

also if you want to improve the behavior you can use GCD, enjoy!

CIContext *ctxt63 = [CIContext contextWithOptions:nil];
        CIFilter *filter63 = [CIFilter filterWithName:@"CIColorControls"];
        [filter63 setDefaults];
        [filter63 setValue:input forKey:kCIInputImageKey];
        [filter63 setValue:@1.8 forKeyPath:kCIInputSaturationKey];
        [filter63 setValue:[NSNumber numberWithFloat:0.8] forKey:@"inputBrightness"];
        [filter63 setValue:[NSNumber numberWithFloat:3.0] forKey:@"inputContrast"];

        CIImage *output63 = [filter63 outputImage];

        //Aplicar el filtro en segundo plano
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            CGImageRef res63 = [ctxt63 createCGImage:output63 fromRect:[output63 extent]];

            dispatch_async(dispatch_get_main_queue(), ^{                   
                UIImage *img63 = [UIImage imageWithCGImage:res63];
                CGImageRelease(res63);
                self.photoView.image = img63;           
            });
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM