سؤال

I have implemented a group filter(GPUImageSepiaFilter, GPUImageExposureFilter, GPUImageSepiaFilter) for image editing. And I have one slider which is used to set custom "Exposure" (setExposure:) value. On the "didValueChanged" action method of slider, I am refreshing the image preview by calling "picture processImage". If I move the slider very fast or when repeatedly scrolling the slider, app crashes for sure due to memory issue.

- (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];    
}

Which is the best way to fix this? Or am I doing anything wrong?

Thanks,
Srinivas

هل كانت مفيدة؟

المحلول

Mine are just some advices about images and GPUImage:

  • The "disk" size image it doesn't represent the real image size, that's because it could have been compressed. The real image size, when it's decompressed in memory and the system ha to handle it is: height*width*n°channel*n°bit_for_each_channel
  • Images should be always loaded lazily, is useless have them around if you are not using them
  • Brad has made a huge change in its framework about framebuffer reuse that had a major improvement on how memory is handled, are you sure that you are using the last version on github?
  • have you tried to profile the app with allocation instruments, maybe the problem is somewhere else, with this tool you can see if the memory grows where you expect
  • imageNamed method caches images and even if they say that this memory will be evicted in memory pressure situation I never had the occasion to see that purge working

I'm not seeing anything wrong with your code in using GPUImage, but I would try to use smaller images (in pixel size) and first of all use allocations.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top