CIFilter with UISlider

So, I have a UISlider that changes the HUE using CIFilter. Its insanely slow because I am influencing the base image while the uislider is being used.

Anyone have suggestions on how to do this more efficiently?

// UI SLIDER -(IBAction)changeSlider:(id)sender { [self doHueAdjustFilterWithBaseImage:currentSticker.image hueAdjust:[(UISlider *)sender value]]; } //Change HUE -(void)doHueAdjustFilterWithBaseImage:(UIImage*)baseImage hueAdjust:(CGFloat)hueAdjust { CIImage *inputImage = [[CIImage alloc] initWithImage:baseImage]; CIFilter * controlsFilter = [CIFilter filterWithName:@"CIHueAdjust"]; [controlsFilter setValue:inputImage forKey:kCIInputImageKey]; [controlsFilter setValue:[NSNumber numberWithFloat:hueAdjust] forKey:@"inputAngle"]; //NSLog(@"%@",controlsFilter.attributes); CIImage *displayImage = controlsFilter.outputImage; CIContext *context = [CIContext contextWithOptions:nil]; if (displayImage == nil){ NSLog(@"Display NADA"); } else { NSLog(@"RETURN Image"); currentSticker.image = [UIImage imageWithCGImage:[context createCGImage:displayImage fromRect:displayImage.extent]]; } displayImage = nil; inputImage = nil; controlsFilter = nil; } 
+6
source share
3 answers

You can set the continuous UISlider property to NO. So your changeSlider is only called when the user releases his finger. Here is the Apple doc ?

+2
source

Your problem is that you keep updating the context. Put the context as a property and initialize it once in your initializer, then use it again and again and you will see a significant increase in performance.

+2
source

I assume that you are changing the amazing behavior you need, frequent updates with little movement are good! and this is best for users. Therefore, do not change this behavior, but rather work on your algorithm to achieve greater optimization. Check out this previously asked question, which contains some helpful tips.

How to implement fast image filters on the iOS platform


My move will be, keep updating the properties of the slider, but try to compose something that the update does when the slider hits a number that is an integer decimal (funny term and probably incorrect). I mean, when the slider goes through 10,000, 20,000, 30,000. Only then refresh the image, and then refresh it for each individual point. Hope this makes sense.

EDIT:

Make your own

Input magicians and filter variables like iVar. and check that they are already selected, then reuse it, and then create it every time.

+1
source

Source: https://habr.com/ru/post/918264/


All Articles