2

次のように、輝度係数とコントラスト係数で画像をフィルタリングする方法を作成しました。

- (UIImage*)image:(UIImage*)image withBrightness:(float)brightness contrast:(float)contrast{
    GPUImagePicture *imagePicture = [[GPUImagePicture alloc] initWithImage:image];
    GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
    GPUImageContrastFilter *contrastFilter = [[GPUImageContrastFilter alloc] init];

    [imagePicture addTarget:brightnessFilter];
    [brightnessFilter addTarget:contrastFilter];

    brightnessFilter.brightness = brightness; // set brightness
    contrastFilter.contrast = contrast;       // set contrast

    [imagePicture processImage];
    UIImage *filteredImage = [contrastFilter imageFromCurrentlyProcessedOutput];
    return filteredImage;
}

この実装を呼び出すと、エラーが発生します: <Error>: CGContextDrawImage: invalid context 0x0

GPUImage を使用して明るさとコントラストの調整を正しく実装する方法は?

4

1 に答える 1

0

おそらくグループ フィルターを作成する必要があります。このサンプル コードを確認してください。

    GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init];
    [groupFilter addTarget:edit.currentFilter];

    //create a brightness filter
    GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc]init];
    [brightnessFilter setBrightness:brightnessValue];

    //create a contrast filter
    GPUImageContrastFilter *contrastFilter = [[GPUImageContrastFilter alloc]init];
    [contrastFilter setContrast:contrastValue];

    //create a exposure filter
    GPUImageExposureFilter *exposureFilter =[[GPUImageExposureFilter alloc]init];
    [exposureFilter setExposure:exposureValue];

    //add brightness,contrast,exposure filters to group filter
    [groupFilter addFilter:brightnessFilter];
    [groupFilter addFilter:contrastFilter];
    [groupFilter addFilter:exposureFilter];


    [edit.currentFilter addTarget:brightnessFilter];
    [brightnessFilter addTarget: contrastFilter];
    [contrastFilter addTarget: exposureFilter];
    //setting initial and terminal filters
    [(GPUImageFilterGroup *) groupFilter setInitialFilters:[NSArray arrayWithObject:edit.currentFilter]];
    [(GPUImageFilterGroup *) groupFilter setTerminalFilter:exposureFilter];


    //apply it to the GPUImagePicture
于 2013-10-02T10:46:38.817 に答える