å¦çé ãã£ã½ãããªã¢ã«ã¿ã¤ã ãã£ã«ã¿ã¼ã«ã¯åããªãã£ã½ããã©ãç»åã«ãã£ã«ã¿ã¼æ¸ããã®ã¯ãã¨ã¦ãæ°è»½ã«åºæ¥ãã
ãªã¢ã«ã¿ã¤ã ã«ãã£ã«ã¿ã¼ãããã®ã¯GPUImageãçéãããã®ã§ãå¾æ¥è§¦ãã
ã«ã¡ã©ã®èµ·å
AVFoundationã§ã«ã¡ã©ã表示ããã¨ã¦ãçããµã³ãã« #Objective-C - Qiita [ãã¼ã¿]
ããã®ã³ã¼ãã³ãããã¾ããã
ãã£ã«ã¿ã¼ããã
CoreImage.frameworkå¿ è¦ãªã®ã§è¿½å ãã
CIFilterã®ä½¿ãæ¹!ã¿ãããªè¨äºã®å¤ãã¯ã[CIFilter filterWithName:keysAndValues:]
ã使ã£ã¦ããã©ãè¥å¹²åããã«ããã®ã§ããã£ã«ã¿ã¼ã«å¿
è¦ãªãã©ã¡ã¿ã®è¨å®ã¯KVC使ã£ã¦Keyã¨Valueã®è¨å®ãã¦ãã¾ãã
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { UIImage *rawCaptureImage = [self imageFromSampleBufferRef:sampleBuffer]; UIImage *filterImage = nil; // ããã§ãã£ã«ã¿ã¼é¢æ°å¼ã¶æãã®æ³å® }
ã»ãã¢
intensityã¯ã©ã®ãããEffectãããããã®å²åãæå°0.0fãæ大1.0f
+ (UIImage *)sepiaToneFilterWithImage:(UIImage *)srcImage intensity:(float)intensity { CIImage *ciImage = [[CIImage alloc] initWithImage:srcImage]; CIFilter *ciFilter = [CIFilter filterWithName:@"CISepiaTone"]; [ciFilter setValue:ciImage forKey:kCIInputImageKey]; [ciFilter setValue:@(intensity) forKey:[NSString stringWithFormat:@"inputIntensity"]]; CIContext *ciContext = [CIContext contextWithOptions:nil]; CGImageRef cgImageRef = [ciContext createCGImage:[ciFilter outputImage] fromRect:[[ciFilter outputImage] extent]]; UIImage *filteringImage = [UIImage imageWithCGImage:cgImageRef scale:1.0f orientation:UIImageOrientationUp]; CGImageRelease(cgImageRef); return filteringImage; }
è²ã®å転
+ (UIImage *)colorInvertWithImage:(UIImage *)srcImage { CIImage *ciImage = [[CIImage alloc] initWithImage:srcImage]; CIFilter *ciFilter = [CIFilter filterWithName:@"CIColorInvert"]; [ciFilter setValue:ciImage forKey:kCIInputImageKey]; CIContext *ciContext = [CIContext contextWithOptions:nil]; CGImageRef cgImageRef = [ciContext createCGImage:[ciFilter outputImage] fromRect:[[ciFilter outputImage] extent]]; UIImage *filteringImage = [UIImage imageWithCGImage:cgImageRef scale:1.0f orientation:UIImageOrientationUp]; CGImageRelease(cgImageRef); return filteringImage; }
ãã¹ã¿ã©ã¤ãº
inputLevelsã¯ã©ã®ããããã¹ã¿ã©ã¤ãºãããï¼æå°0.0fãæ大30.0f
+ (UIImage *)posterizeWithImage:(UIImage *)srcImage inputLevels:(float)inputLevels { CIImage *ciImage = [[CIImage alloc] initWithImage:srcImage]; CIFilter *ciFilter = [CIFilter filterWithName:@"CIColorPosterize"]; [ciFilter setValue:ciImage forKey:kCIInputImageKey]; [ciFilter setValue:@(inputLevels) forKey:[NSString stringWithFormat:@"inputLevels"]]; CIContext *ciContext = [CIContext contextWithOptions:nil]; CGImageRef cgImageRef = [ciContext createCGImage:[ciFilter outputImage] fromRect:[[ciFilter outputImage] extent]]; UIImage *filteringImage = [UIImage imageWithCGImage:cgImageRef scale:1.0f orientation:UIImageOrientationUp]; CGImageRelease(cgImageRef); return filteringImage; }
ãã¨è²ã ãããã©ãå ¬å¼ã®ããã¥ã¡ã³ãèªãã ã»ããæ©ãæ°ãããã
åãå¤ããã©å¬ãããã¨ã«æ¥æ¬èªããã¥ã¡ã³ãã§ãã