我正在尝试对图像应用一些过滤器,所以我GPUImageFilterGroup
用来混合过滤器,但我的应用程序崩溃,这是我的代码:
- (IBAction)effectApply:(id)sender { GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init]; GPUImagePicture *stillImage= [[GPUImagePicture alloc]initWithImage:_img.image]; GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc]init]; [brightnessFilter setBrightness:.4]; GPUImageContrastFilter *contrastFilter = [[GPUImageContrastFilter alloc]init]; [contrastFilter setContrast:2.0]; GPUImageExposureFilter *exposureFilter =[[GPUImageExposureFilter alloc]init]; [exposureFilter setExposure:.2]; [groupFilter addFilter:brightnessFilter]; [groupFilter addFilter:contrastFilter]; [groupFilter addFilter:exposureFilter]; [(GPUImageFilterGroup *) groupFilter setInitialFilters:[NSArray arrayWithObject: brightnessFilter]]; [(GPUImageFilterGroup *) groupFilter setTerminalFilter:exposureFilter]; [stillImage addTarget:filter]; [filter useNextFrameForImageCapture]; [stillImage processImage]; UIImage *currentFilteredVideoFrame = [filter imageFromCurrentFramebuffer]; _img.image = currentFilteredVideoFrame; }
崩溃日志:
2014-07-10 15:27:03.955 Effect Test[65595:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x00000001021b9495 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000101f1899e objc_exception_throw + 43 2 CoreFoundation 0x0000000102170374 -[__NSArrayM insertObject:atIndex:] + 820 3 Effect Test 0x0000000100012077 __46-[GPUImageOutput addTarget:atTextureLocation:]_block_invoke + 103 4 libdispatch.dylib 0x000000010370e72d _dispatch_client_callout + 8 5 libdispatch.dylib 0x00000001036fd5d0 _dispatch_barrier_sync_f_invoke + 57 6 Effect Test 0x000000010001147c runSynchronouslyOnVideoProcessingQueue + 108 7 Effect Test 0x0000000100011fb0 -[GPUImageOutput addTarget:atTextureLocation:] + 272 8 Effect Test 0x000000010001637c -[GPUImagePicture addTarget:atTextureLocation:] + 108 9 Effect Test 0x0000000100011e56 -[GPUImageOutput addTarget:] + 86 10 Effect Test 0x000000010000167b -[ViewController effectApply:] + 667 11 UIKit 0x0000000100ac6f06 -[UIApplication sendAction:to:from:forEvent:] + 80 12 UIKit 0x0000000100ac6eb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 13 UIKit 0x0000000100ba3880 -[UIControl _sendActionsForEvents:withEvent:] + 203 14 UIKit 0x0000000100ba2dc0 -[UIControl touchesEnded:withEvent:] + 530 15 UIKit 0x0000000100afdd05 -[UIWindow _sendTouchesForEvent:] + 701 16 UIKit 0x0000000100afe6e4 -[UIWindow sendEvent:] + 925 17 UIKit 0x0000000100ad629a -[UIApplication sendEvent:] + 211 18 UIKit 0x0000000100ac3aed _UIApplicationHandleEventQueue + 9579 19 CoreFoundation 0x0000000102148d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 20 CoreFoundation 0x00000001021485f2 __CFRunLoopDoSources0 + 242 21 CoreFoundation 0x000000010216446f __CFRunLoopRun + 767 22 CoreFoundation 0x0000000102163d83 CFRunLoopRunSpecific + 467 23 GraphicsServices 0x0000000104f93f04 GSEventRunModal + 161 24 UIKit 0x0000000100ac5e33 UIApplicationMain + 1010 25 Effect Test 0x0000000100001bc3 main + 115 26 libdyld.dylib 0x000000010395f5fd start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
小智.. 5
GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init]; [groupFilter addTarget:brightnessFilter]; [brightnessFilter addTarget: contrastFilter]; [contrastFilter addTarget: exposureFilter]; [(GPUImageFilterGroup *) groupFilter setInitialFilters:[NSArray arrayWithObject: brightnessFilter]]; [(GPUImageFilterGroup *) groupFilter setTerminalFilter:exposureFilter]; [stillImage addTarget:groupFilter];
希望能帮助到你
GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init]; [groupFilter addTarget:brightnessFilter]; [brightnessFilter addTarget: contrastFilter]; [contrastFilter addTarget: exposureFilter]; [(GPUImageFilterGroup *) groupFilter setInitialFilters:[NSArray arrayWithObject: brightnessFilter]]; [(GPUImageFilterGroup *) groupFilter setTerminalFilter:exposureFilter]; [stillImage addTarget:groupFilter];
希望能帮助到你