0
我寫了一些代碼,它創建了一個過濾器,並且可以通過UISlider進行控制。 但是,如果我滑動UISlider,該應用程序崩潰。dataProvider是0x0/nil(GPUImage Framework)
我的代碼:
.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應用是新的。
我在亮度過濾器的.m文件中已經添加了這2種方法。但它仍然不起作用。我重命名了實例變量。 – DeviJP
好的。現在我要走另一條路了。我用一種方法來做(代碼在我的答案中)。如果我向前滑動UISlider,所有工作正常。但是如果我向後滑動UISlider,過濾器變得越來越強。你知道爲什麼嗎? – DeviJP
@DeviJP - 問題的原因在於,您將亮度應用於您已經應用了先前亮度傳球的內容,而不是您的源圖像。這不是你想要做的。再一次,你真的不應該重新創建圖片並過濾每一個值的變化,並且你不應該在每次傳遞時將UIImage設置爲UIImageView。按照SimpleImageFilter示例中提供的示例創建GPUImagePicture並過濾一次,將它們指向GPUImageView,並僅更新過濾器的值以提供實時預覽。 –