使用BradLarson/GPUImage的图像过滤效果**问题

sma*_*nja 3 objective-c ios4 ios

我想为UIImage添加不同的效果.目前我正在尝试使用GUIImage库.https://github.com/BradLarson/GPUImage 但是,我无法运行提供的大部分示例.只有我的工作示例是FilterShowcase它很棒.

但问题是,它的工作只与相机有关.我想要的是将静态图像加载到UIImageView并应用这些过滤器.

我试过了,但无法做到.

这是我尝试的方式

  - (void)setupFilter;
{
//    videoCamera = [[GPUImageVideoCamera alloc]  initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
////    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
//    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;


UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];

imgView.Image=[UIImage imageNamed:@"WID-small.jpg"];

[self.view addSubview:imgView];

BOOL needsSecondImage = NO;

switch (filterType)
{
    case GPUIMAGE_SEPIA:
    {
        self.title = @"Sepia Tone";
        self.filterSettingsSlider.hidden = NO;

        [self.filterSettingsSlider setValue:1.0];
        [self.filterSettingsSlider setMinimumValue:0.0];
        [self.filterSettingsSlider setMaximumValue:1.0];

        filter = [[GPUImageSepiaFilter alloc] init];

        sourcePicture = [[GPUImagePicture alloc] initWithImage:imgView.image smoothlyScaleOutput:YES];
        [sourcePicture processImage];            
        [sourcePicture addTarget:filter];




    }; break;
Run Code Online (Sandbox Code Playgroud)

实际上我试图做的是,加载静止图像而不是videoCamera.但它不起作用.如果有人可以帮助我,它非常感谢.

Bra*_*son 12

首先,有几个原因导致其他示例应用程序可能无法为您构建.如本答案中所述,请确保您在Xcode窗口的左上角选择了应用程序的方案,而不是GPUImage框架项目.如果更改没有帮助,退出Xcode,从DerivedData目录中删除相关项目目录,然后重新启动Xcode.由于最近的Xcode版本中存在错误,有时似乎需要这样做.

项目文档中描述了图像的过滤,该文档位于Readme.md文件中以及上面链接的页面上.特别是,请参阅标题为"处理静止图像"的部分:

有两种方法可以处理静止图像并创建结果.您可以通过创建静态图像源对象并手动创建过滤器链来实现此目的的第一种方法:

UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];

[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];

UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];
Run Code Online (Sandbox Code Playgroud)

对于要应用于图像的单个过滤器,您只需执行以下操作:

GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];
Run Code Online (Sandbox Code Playgroud)

SimpleImageFilter示例应用程序显示了如何更详细地执行此操作.