【问题标题】:iOS capture image form GPUImageiOS抓图形式GPUImage
【发布时间】:2015-08-26 10:28:13
【问题描述】:

我正在尝试使用使用 GPUImage 的应用程序捕获图像。我的相机是这样设置的

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

我使用自定义过滤器:

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

然后我使用此代码进行相机捕捉:

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

我得到的只是白色图片,RGB 为 0,0,0。 我尝试在 IBAction 和 rac_signalForControlEvents 中保存,我使用了调度但没有任何改变。谁能告诉我我做错了什么?

谢谢, 亚历克斯

【问题讨论】:

    标签: ios xcode gpuimage image-capture


    【解决方案1】:

    尝试像这些一样使用 GPUImageStillCamera..

    在您的 .h 文件中..

    GPUImageStillCamera *stillCamera;
    GPUImageView * filterView;
    

    在您的 .m 文件中查看didload..

    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];
    

    在用于捕获图像的 UIButtons 单击事件上执行这些操作,希望对您有所帮助..

    [stillCamera capturePhotoAsImageProcessedUpToFilter:selectedFilter withCompletionHandler:^(UIImage *processedImage, NSError *error)
     {
            UIImageWriteToSavedPhotosAlbum(processedImage, self, nil, nil);
     }];
    

    【讨论】:

      【解决方案2】:
      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];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-22
        相关资源
        最近更新 更多