我知道我可以使用静态相机的capturePhotoAsImageProcessedUpToFilter
方法,但它会发出快门咔哒声,我还有一些处理要做,所以我不希望它发出声音。
我尝试使用过滤器的 imageFromCurrentFramebuffer
方法,但这总是为零。
CGRect frame = CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width);
_backgroundImageView = [[GPUImageView alloc] initWithFrame:frame];
[self.view insertSubview:_backgroundImageView atIndex:0];
_camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:AVCaptureDevicePositionBack];
_camera.outputImageOrientation = UIInterfaceOrientationLandscapeRight;
filter = [[GPUImageBrightnessFilter alloc] init];
filter.brightness = 0;
[_camera addTarget: filter];
[filter addTarget:_backgroundImageView];
[_camera startCameraCapture];
// processTimer is to periodically do processing on what's being shown on screen.
processTimer =[NSTimer timerWithTimeInterval:10 target:self selector:@selector(processImage) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:processTimer forMode:NSRunLoopCommonModes];
-(void) processImage {
[processTimer invalidate];
UIImage *testImage = [filter imageFromCurrentFramebuffer]; // always nil
[_camera capturePhotoAsImageProcessedUpToFilter:filter withCompletionHandler:^(UIImage *processedImage, NSError *error) {
// additional processing here ... don't want shutter sound yet.
}];
}
最佳答案
您可以使用以下方法从链中的任何过滤器中获取没有快门声的 UIImage:- (UIImage *)imageFromCurrentFramebuffer
的 GPUImageOutput
它的子类:GPUImageVideoCamera
, GPUImageStillCamera
, GPUImageFilter
, ETC。
如果您的目标是显示视口(viewport),请使用 GPUImageView
作为过滤器链中的最后一项。
关于ios - 如何从 GPUImage 相机获取 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24725614/