GPUImage将过滤器应用于GPUImageView

时间:2015-01-23 02:14:54

标签: ios objective-c gpuimage gpuimagestillcamera

我使用GPUImageStillCamera拍照并将图片加载到GPUImageView

现在我如何将过滤器应用于静态GPUImageView?

我在网上看到的唯一例子是首先创建一个GPUImagePicture(需要一个UIImage),但是当我可以将过滤器应用到GPUImageView时,必须从GPUImageView创建一个UIImage并将其加载到GPUImagePicture中似乎相当浪费直。但我不知道如何

我试过了:

  GPUImageFilter *sepiaFilter [[GPUImageSepiaFilter alloc]init];
  [sepiaFilter addTarget:gpuImageView];

  //and then tried these in a bunch of different orders
  [filter useNextFrameForImageCapture];
  [currentFilter endProcessing];
  [currentFilter imageFromCurrentFramebuffer];

编辑:这是我如何将图像加载到GPUImageView

self.stillCamera = [[GPUImageStillCamera alloc]
                        initWithSessionPreset:AVCaptureSessionPresetPhoto
                        cameraPosition:AVCaptureDevicePositionFront];
self.stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
self.filterEmpty = [[GPUImageGammaFilter alloc] init];

[self.stillCamera addTarget:self.filterEmpty];


[self.filterEmpty addTarget:self.capturedImageView];
[self.stillCamera startCameraCapture];


[self.stillCamera capturePhotoAsJPEGProcessedUpToFilter:self.filterEmpty withCompletionHandler:^(NSData *processedJPEG, NSError *error){

[self.stillCamera stopCameraCapture];

//and then from here the gpuimageview is loaded with the taken picture

1 个答案:

答案 0 :(得分:0)

在GPUImageView上有一个常规的图像视图。

让我们称之为UIImageVIew imageView

[self.stillCamera capturePhotoAsImageProcessedUpToFilter:self.filterEmpty 
   withCompletionHandler:^(UIImage *processedImage, NSError *error) {
      imageView.image = processedImage;
      //stop, dispose of, or just continue with the camera,
      //depending on what you want with your app.
}];

至少,这就是我在实时照片过滤应用上的表现方式,而且效果很好。

相关问题