brightness control slider is really slow in responding in ios -
i need help.
i creating simple image processing app, load image camera roll or take picture. have brightness control (slider) adjust brightness of image. problem slider works in real time on simulator, on ipad there small delay in response. have tried everything, don't seem have luck.
please help. have seen other apps slider works smoothly without delay. doing wrong?
thanks
i'm going take guess on things left out of initial question.
1) clarify, problem is: movement of slider not smooth. 2) also, result of, or in combination with, ui roughness, there delay in change image.
i'm not sure implementation looks like, but, sounds you're doing work and/or on main thread.
so, heres functioning implementation might do:
- (void)sliderchanged:(uislider *)sender { [self adjustimagebrightnesswithvalue:sender.value; } - (void)adjustimagebrightnesswithvalue:(cgfloat)value { [self cancelcurrentwork]; // maintain reference operation , cancel [self adjustimagebrightnessasyncwithvalue:(cgfloat)value originalimage:self.imageview.image completion:^(uiimage *finalimage) { self.imageview.image = finalimage; } }
adjustimagebrightnessasyncwithvalue takes value, original image, , completion block. creates operation (via nsoperation or nsoperationqueue, both) , keeps track of operation. operation applies algorithm original image in background. once done, completion block sets final image in image view, on main thread.
the things happen on main thread are: slider changed callback, canceling previous work, starting new work, , setting final image. else should happen in background. canceling work optimization case user moves slider fast image modified before value changes again. once slider doesn't change long enough modification, result visible. slider should smooth because nothing blocking main thread.
edit
using operation queue... declare member variable:
nsoperationqueue *m_queue;
...
initialize in init method:
m_queue = [nsoperationqueue new]; m_queue.maxconcurrentoperationcount = 1; // 1 brightness calculation @ time , there no concurrency issues.
...
- (void)adjustimagebrightnesswithvalue:(cgfloat)value { [m_queue cancelalloperations]; [m_queue addoperationwithblock:^ { uiimage *adjustedimage = [mainimage brightness:value]; // not sure method coming from, code assumes returns copy of mainimage brightness adjusted. dispatch_async(dispatch_get_main_queue(), ^ { imageview.image = adjustedimage; }); }]; }
also, aside, might take @ gpuimage, discussed here: http://nshipster.com/gpuimage/ numerous fast, powerful image modification techniques/apis.
Comments
Post a Comment