[英]How can I get a UIImage from GPUImage camera?
我知道我可以使用靜態相機的capturePhotoAsImageProcessedUpToFilter
方法,但是它會發出快門咔嗒聲,我還有一些處理要做,所以我不希望它聽起來。
我嘗試使用過濾器的imageFromCurrentFramebuffer
方法,但這總是imageFromCurrentFramebuffer
nil。
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
等。
如果您的目的是顯示視口,請使用GPUImageView
作為過濾器鏈中的最后一項。
好吧..終於找到了答案。 我需要在調用imageFromCurrentFramebuffer之前在過濾器上調用useNextFrameForImageCapture。 有時仍然返回nil,但可以得到我所需的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.