ios - 如何从 GPUImage 相机获取 UIImage?

标签 ios gpuimage

我知道我可以使用静态相机的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/

相关文章:

ios - Swift 3 如何为索引 UICollectionView 中的每个项目显示不同的数据

ios - GPUImage 多个实时视频

filter - 使用 GPUImage 框架在过滤器链之间切换

ios - 使用 GPUImage 对视频进行色度过滤?

ios - MKMapKit 上的高斯模糊

ios - 为什么 alpha 混合渐变纹理会在 OpenGL ES 2.0 中产生意想不到的结果?

ios - 禁用安全区域布局指南

ios - 如何在 iOS Speech API 上检测语音开始

ios - 保持 iOS 应用程序处于事件状态以使用 MQTT 协议(protocol)

ios - GPUImage 可用于 iOS 8 吗?