我编写了一些创建过滤器的代码,可以通过UISlider进行控制。 但如果我滑动UISlider,应用程序崩溃了。
我的代码:
.m文件:
- (void) viewDidLoad {
[_sliderBrightness addTarget:self action:@selector(brightnessFilter) forControlEvents:UIControlEventValueChanged];
_sliderBrightness.minimumValue = -1.0;
_sliderBrightness.maximumValue = 1.0;
_sliderBrightness.value = 0.0;
}
- (IBAction)sliderBrightness:(UISlider *)sender {
CGFloat midpoint = [(UISlider *)sender value];
[(GPUImageBrightnessFilter *)brightFilter setBrightness:midpoint - 0.1];
[(GPUImageBrightnessFilter *)brightFilter setBrightness:midpoint + 0.1];
[sourcePicture processImage];
}
- (void) brightnessFilter {
UIImage *inputImage = _imgView.image;
sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
brightFilter = [[GPUImageBrightnessFilter alloc] init];
GPUImageView *imgView2 = (GPUImageView *)self.view;
[brightFilter useNextFrameForImageCapture];
[sourcePicture addTarget:brightFilter];
[sourcePicture processImage];
UIImage* outputImage = [brightFilter imageFromCurrentFramebufferWithOrientation:0];
[_imgView setImage:outputImage];
}
错误:
GPUImageFramebuffer.m:
}
else
{
[self activateFramebuffer];
rawImagePixels = (GLubyte *)malloc(totalBytesForImage);
glReadPixels(0, 0, (int)_size.width, (int)_size.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels);
dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels, totalBytesForImage, dataProviderReleaseCallback);
[self unlock]; // Don't need to keep this around anymore
}
在这行代码中:
[self activateFramebuffer];
错误讯息:
Thread 1: EXC_BAD_ACCESS (code=EXC_1386_GPFLT)
控制台:
self = (GPUImageFramebuffer *const) 0x10a0a6960
rawImagePixels = (GLubyte *) 0x190
dataProvider = (CGDataProviderRef) 0x0
renderTarget = (CVPixelBufferRef) 0x8
也许dataProvider导致崩溃,但我真的不知道,因为我是开发iOS应用程序的新手。
答案 0 :(得分:0)
这显然不起作用(甚至不应该编译),因为GPUImageBrightnessFilter没有-setTopFocusLevel:
或-setBottomFocusLevel:
方法。您从我的示例应用程序复制了这个,而没有将这些方法更改为适合于亮度过滤器(即brightness
属性)的方法。
同时拥有brightnessFilter
实例变量和-brightnessFilter
方法也令人困惑(并且可能存在问题)。您可能希望重命名前者以清楚地表明您正在执行过滤器和源图像的初始设置。您还需要在视图控制器的设置中调用它(在加载Nib之后)。