简体   繁体   English

iOS捕获图像形式GPUImage

[英]iOS capture image form GPUImage

I am trying to capture an image with an app that uses GPUImage. 我正在尝试使用使用GPUImage的应用程序捕获图像。 I have the camera set up like this 我有这样的相机设置

self.videoCamera = [[GPUImageVideoCamera alloc]
                    initWithSessionPreset:AVCaptureSessionPresetHigh
                    cameraPosition:AVCaptureDevicePositionBack];
_videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
[_videoCamera startCameraCapture];
[_videoCamera addTarget:sample1ImageView];

and i use a custom filter: 我使用自定义过滤器:

radFilter = [[GPUImageCustomFilter alloc] init];
[_videoCamera addTarget:cusFilter];
[cusFilter addTarget:imageView];

I then use this code for the camera capture: 然后,我将以下代码用于摄像头捕获:

[_videoCamera pauseCameraCapture];
[radFilter forceProcessingAtSize:CGSizeMake(600, 600)];
[radFilter useNextFrameForImageCapture];
UIImage* capturedImage = [radFilter imageFromCurrentFramebuffer];
UIImageWriteToSavedPhotosAlbum(capturedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[_videoCamera resumeCameraCapture];

and all i get is white pictures, with rgb 0,0,0. 我得到的是白色图片,RGB 0,0,0。 I tried saving both in an IBAction and in a rac_signalForControlEvents,i used dispatch but nothing changed. 我尝试将其保存在IBAction和rac_signalForControlEvents中,但我使用了调度,但没有任何更改。 Can anyone tell me what am i doing wrong? 谁能告诉我我在做什么错?

Thank you, Alex 谢谢亚历克斯

try using GPUImageStillCamera like these.. 尝试像这样使用GPUImageStillCamera。

in your .h file.. 在您的.h文件中。

GPUImageStillCamera *stillCamera;
GPUImageView * filterView;

in your .m files viewdidload.. 在您的.m文件viewdidload中。

selectedFilter = [[GPUImageFilter alloc]init];
filterView=[[GPUImageView alloc]init];

stillCamera=[[GPUImageStillCamera alloc]initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionFront];
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
[stillCamera addTarget:selectedFilter];
[selectedFilter addTarget:filterView];
[stillCamera startCameraCapture];

on the UIButtons click event for capturing image do these,i hope it helps.. 在UIButtons click事件上捕获图像可以做到这些,希望对您有所帮助。

[stillCamera capturePhotoAsImageProcessedUpToFilter:selectedFilter withCompletionHandler:^(UIImage *processedImage, NSError *error)
 {
        UIImageWriteToSavedPhotosAlbum(processedImage, self, nil, nil);
 }];
You can use this code to capture the image.

- (UIImage *) screenshot {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);

    [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (IBAction)btnCaptureClicked:(id)sender
{
    [videoCamera pauseCameraCapture];
    [filter useNextFrameForImageCapture];
    //[filter imageFromCurrentFramebuffer];
    UIImage *capturedImage= [self screenshot];
    if(capturedImage != nil)
    {
        UIImageWriteToSavedPhotosAlbum(capturedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }
    [videoCamera resumeCameraCapture];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM