gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:40:43 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com