我正在使用BradLarson的GPUImage库来过滤图像。 我在我的项目中使用this代码。
GPUImagePicture *staticPicture;
过滤器的应用是这样的 -
-(void) setFilter:(int) index {
switch (index) {
case 1:{
filter = [[GPUImageContrastFilter alloc] init];
[(GPUImageContrastFilter *) filter setContrast:1.75];
} break;
case 2: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"crossprocess"];
} break;
case 3: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"02"];
} break;
case 4: {
filter = [[GrayscaleContrastFilter alloc] init];
} break;
case 5: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"17"];
} break;
case 6: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"aqua"];
} break;
case 7: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"yellow-red"];
} break;
case 8: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"06"];
} break;
case 9: {
filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"purple-green"];
} break;
default:
filter = [[GPUImageFilter alloc] init];
break;
}
现在我想在不改变当前应用过滤器的情况下增加GPUImage的亮度。如何做到这一点?
答案 0 :(得分:0)
包括以下方法
-(UIImage*)applyFilterForImage:(UIImage*)img value:(NSNumber*)filterValue
{
switch (type) {
case kPhotoBrightness:
self.filterImage = [self applyBrightnessForImage:img value:filterValue];
break;
case kPhotoContrast:
self.filterImage = [self applyContrastForImage:img value:filterValue];
break;
case kPhotoSaturation:
self.filterImage = [self applySaturationForimage:img value:filterValue];
break;
case kPhotoHue:
self.filterImage = [self applyHueForImage:img value:filterValue];
break;
case kPhotoSharpness:
self.filterImage = [self applySharpnessForImage:img value:filterValue];
break;
default:
break;
}
return self.filterImage;
}
-(UIImage*)applyBrightnessForImage:(UIImage*)img value:(NSNumber*)filterValue {
GPUImageBrightnessFilter *brightnessFilter = (GPUImageBrightnessFilter*)self.filter;
[brightnessFilter setBrightness:[filterValue floatValue]];
return [self outputImageForFilter:brightnessFilter andImage:img];
}
//output the filtered image
-(UIImage*)outputImageForFilter:(GPUImageOutput<GPUImageInput>*)_filter andImage:(UIImage*)_image {
GPUImagePicture *filteredImage = [[GPUImagePicture alloc]initWithImage:_image];
[filteredImage addTarget:_filter];
[filteredImage processImage];
return [_filter imageFromCurrentlyProcessedOutputWithOrientation:_image.imageOrientation];
}