2

我目前正在尝试使用 GPUImage 显示直方图。我目前有以下代码:

GPUImageOutput<GPUImageInput> *filter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramLuminance];
[self.stillCamera  removeTarget:filter];
GPUImageGammaFilter *gammaFilter = [[GPUImageGammaFilter alloc] init];
[self.stillCamera  addTarget:gammaFilter];
[gammaFilter addTarget:filter];

GPUImageHistogramGenerator *histogramGraph = [[GPUImageHistogramGenerator alloc] init];

[histogramGraph forceProcessingAtSize:CGSizeMake(500.0, 500)];
[filter addTarget:histogramGraph];

GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 0.75;
[blendFilter forceProcessingAtSize:CGSizeMake(500, 500)];

[self.stillCamera addTarget:blendFilter];
[histogramGraph addTarget:blendFilter];

[blendFilter addTarget:previewView];

上面显示了在我的 previewView 上过度播放的直方图。(但它确实闪烁,另一个问题,另一天)

我想在视图上特定位置的较小视图上显示此直方图。我怎样才能做到这一点?

4

1 回答 1

3

要在单独的视图中显示直方图,您需要在主视图中添加另一个GPUImageView并指向直方图过滤器。这是基于SimpleImageFilter示例的源代码。

- (void)loadView
{    
    CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];

    GPUImageView *primaryView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
    self.view = primaryView;

    UIImage *inputImage = [UIImage imageNamed:@"WID-small.jpg"];
    GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];

    // Creating another view to show histogram
    GPUImageView *histView = [[GPUImageView alloc] initWithFrame:CGRectMake(mainScreenFrame.size.width - 100, mainScreenFrame.size.height - 100, 100, 100)];
    [primaryView addSubview:histView];

    // Create histogram filter and generator and point it to histogram view
    GPUImageOutput<GPUImageInput> *histFilter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramLuminance];
    GPUImageOutput<GPUImageInput> *histGenerator = [[GPUImageHistogramGenerator alloc] init];
    [histGenerator forceProcessingAtSize:histView.sizeInPixels];
    [sourcePicture addTarget:histFilter];
    [histFilter addTarget:histGenerator];
    // Note target - hist view
    [histGenerator addTarget:histView];

    // Setup sepia filter just to show main picture
    GPUImageOutput<GPUImageInput> *sepiaFilter = [[GPUImageSepiaFilter alloc] init];
    [sepiaFilter forceProcessingAtSize:primaryView.sizeInPixels];
    [sourcePicture addTarget:sepiaFilter];
    // Note target - main view
    [sepiaFilter addTarget:primaryView];

    [sourcePicture processImage];
}

最终结果:
在此处输入图像描述

于 2015-05-01T18:44:50.660 回答