我已经实现了一个用于图像编辑的组过滤器(GPUImageSepiaFilter、GPUImageExposureFilter、GPUImageSepiaFilter)。我有一个用于设置自定义“曝光”(setExposure:) 值的滑块。在滑块的“didValueChanged”操作方法上,我通过调用“图片processImage”来刷新图像预览。如果我快速移动滑块或重复滚动滑块时,应用程序肯定会由于内存问题而崩溃。
- (void)viewDidLoad {
[super viewDidLoad];
self.originalPicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"IMG_0009.JPG"]];
self.filterGroup = [[GPUImageFilterGroup alloc] init];
GPUImageSepiaFilter *sepiaFilter = [[GPUImageSepiaFilter alloc] init];
[self.filterGroup addFilter:sepiaFilter];
GPUImageExposureFilter *pixellateFilter = [[GPUImageExposureFilter alloc] init];
[pixellateFilter setExposure:0.0f];
[self.filterGroup addFilter:pixellateFilter];
GPUImageSaturationFilter *saturation = [[GPUImageSaturationFilter alloc] init];
[self.filterGroup addFilter:saturation];
[sepiaFilter addTarget:pixellateFilter];
[pixellateFilter addTarget:saturation];
[self.filterGroup setInitialFilters:[NSArray arrayWithObjects:sepiaFilter, pixellateFilter,nil]];
[self.filterGroup setTerminalFilter:saturation];
[self.originalPicture addTarget:self.filterGroup];
GPUImageView *filterView = [[GPUImageView alloc] init];
self.view = filterView;
[self.filterGroup addTarget:filterView];
[self.originalPicture processImage];
[self.slider setMinimumTrackTintColor:[UIColor redColor]];
[self.slider setMaximumTrackTintColor:[UIColor greenColor]];
[self.view addSubview:self.slider];
}
- (IBAction)didChangeValue:(id)sender {
GPUImageExposureFilter *filter = (GPUImageExposureFilter *)[self.filterGroup filterAtIndex:1];
[filter setExposure:self.slider.value];
[self.originalPicture processImage];
}
解决此问题的最佳方法是什么?还是我做错了什么?
谢谢,
斯里尼瓦斯