Bad*_*hah 3 objective-c ios gpuimage
我正在研究GPUImage库.我已经设置了特定的过滤器将应用于Collectionview的didselectitematindexpath方法.这是我的第一个基于GPUImage库的项目.我成功地能够在GPUImageview上应用Filter,但是应用过滤器会花费大量时间.请指导我,如何快速申请.
这是我的代码,
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[filter removeAllTargets];
if (indexPath.row==0) {
NSLog(@"Normal Filter");
}
else if (indexPath.row==1)
{
filter = [[GPUImageSepiaFilter alloc] init];
}
else if (indexPath.row==2)
{
filter = [[GPUImagePixellateFilter alloc] init];
}
else if (indexPath.row==3)
{
filter = [[GPUImagePixellatePositionFilter alloc] init];
}
else if (indexPath.row==4)
{
filter = [[GPUImagePolkaDotFilter alloc] init];
}
else if (indexPath.row==5)
{
filter = [[GPUImageHalftoneFilter alloc] init];
}
else if (indexPath.row==6)
{
filter = [[GPUImageCrosshatchFilter alloc] init];
}
else if (indexPath.row==7)
{
filter = [[GPUImageColorInvertFilter alloc] init];
}
else if (indexPath.row==8)
{
filter = [[GPUImageGrayscaleFilter alloc] init];
}
else if (indexPath.row==9)
{
filter = [[GPUImageMonochromeFilter alloc] init];
[(GPUImageMonochromeFilter *)filter setColor:(GPUVector4){0.0f, 0.0f, 1.0f, 1.f}];
}
else if (indexPath.row==10)
{
filter = [[GPUImageFalseColorFilter alloc] init];
}
else if (indexPath.row==11)
{
filter = [[GPUImageSoftEleganceFilter alloc] init];
}
else if (indexPath.row==12)
{
filter = [[GPUImageMissEtikateFilter alloc] init];
}
else if (indexPath.row==13)
{
filter = [[GPUImageAmatorkaFilter alloc] init];
}
else if (indexPath.row==14)
{
filter = [[GPUImageSaturationFilter alloc] init];
[(GPUImageSaturationFilter *)filter setSaturation:2.0];
}
else if (indexPath.row==15)
{
filter = [[GPUImageContrastFilter alloc] init];
[(GPUImageContrastFilter *)filter setContrast:1.5];
}
else if (indexPath.row==16)
{
filter = [[GPUImageBrightnessFilter alloc] init];
[(GPUImageBrightnessFilter *)filter setBrightness:0.6];
}
else if (indexPath.row==17)
{
filter = [[GPUImageLevelsFilter alloc] init];
}
else if (indexPath.row==18)
{
filter = [[GPUImageRGBFilter alloc] init];
}
else if (indexPath.row==19)
{
filter = [[GPUImageHueFilter alloc] init];
}
else if (indexPath.row==20)
{
filter = [[GPUImageWhiteBalanceFilter alloc] init];
}
else if (indexPath.row==21)
{
filter = [[GPUImageExposureFilter alloc] init];
}
else if (indexPath.row==22)
{
filter = [[GPUImageSharpenFilter alloc] init];
}
else if (indexPath.row==23)
{
filter = [[GPUImageUnsharpMaskFilter alloc] init];
}
else if (indexPath.row==24)
{
filter = [[GPUImageGammaFilter alloc] init];
}
else if (indexPath.row==25)
{
filter = [[GPUImageToneCurveFilter alloc] init];
[(GPUImageToneCurveFilter *)filter setBlueControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 0.75)], nil]];
}
else if (indexPath.row==26)
{
filter = [[GPUImageHighlightShadowFilter alloc] init];
}
else if (indexPath.row==27)
{
filter = [[GPUImageHazeFilter alloc] init];
}
else if (indexPath.row==28)
{
filter = [[GPUImageAverageColor alloc] init];
}
else if (indexPath.row==29)
{
filter = [[GPUImageLuminosity alloc] init];
}
else if (indexPath.row==30)
{
filter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramRGB];
}
else if (indexPath.row==31)
{
filter = [[GPUImageLuminanceThresholdFilter alloc] init];
}
else if (indexPath.row==32)
{
filter = [[GPUImageAdaptiveThresholdFilter alloc] init];
}
else if (indexPath.row==33)
{
filter = [[GPUImageAverageLuminanceThresholdFilter alloc] init];
}
else if (indexPath.row==34)
{
filter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.0, 1.0, 0.25)];
}
[sourcePicture addTarget:filter];
[filter addTarget:self.vwGPUImagview];
[sourcePicture processImage];
}
Run Code Online (Sandbox Code Playgroud)
输出: -
编辑: - 当我写[filter removeAllTarget]一些过滤器没有工作.如果我删除它然后它完全工作.我的错在哪里?
编辑2: - 演示链接
根据提供的代码,你在这里做了一些事情,这将真的减慢这一点.首先,您有一个显然无用的GPUImageVideoCamera,您可以重复多次.这可以删除.
其次,每次要显示单元格时,都会基于UIImage创建新的GPUImagePicture.这样做真的很慢.相反,尝试使用单个共享图像并在显示单元格时将其交换出来.此外,使用的过滤器大小限制为单元格中缩略图的大小-forceProcessingAtSize:.过滤巨型图像没有任何意义,只能显示一个微小的缩略图.
最后,正如我在上面指出的那样,每次更换新过滤器时都会删除过滤器的输出而不是图像的输出.这意味着您交换的每个过滤器都会被添加为图像的输出,但从未被删除.您的图像将构建一个增加的输出过滤器列表,并且处理速度越来越慢.在删除先前过滤器的所有输出的同时,从图片中删除所有输出.
您还可以-forceProcessingAtSize:在此处使用过滤器将其限制为仅显示整个显示的大小,这可能仍然小于源图像.
| 归档时间: |
|
| 查看次数: |
639 次 |
| 最近记录: |