gpt4 book ai didi

ios - GPUImage 在另一个 View 中显示直方图

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:23 32 4
gpt4 key购买 nike

我目前正在尝试使用 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 上过度播放的直方图。 (但是它确实会闪烁,另一个问题,另一天)

我想在 View 上特定位置的较小 View 上显示此直方图。我该怎么做?

最佳答案

要在单独的 View 中显示直方图,您需要将另一个 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];
}

最终结果:
enter image description here

关于ios - GPUImage 在另一个 View 中显示直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29870565/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com