Core Image Filter iOS UISlider -
i'm trying implement sepia filter on image loaded ui view photo library.
i have ui slider...range -1 1. , applying effect sepia.
the problem i'm having is, on effect getting summed up. like...if put slider 1, move 0. doesn't bring image original form. , move 1..total sepia applied 2 times.
- (ibaction)slidermove:(id)sender { currentvalue=_slidervalue.value; if (currentbutton==1) { //1 ciimage *beginimage = [ciimage imagewithdata: uiimagepngrepresentation(self.imageview.image)]; //2 cicontext *context = [cicontext contextwithoptions:nil]; //3 cifilter *filter = [cifilter filterwithname:@"cisepiatone" keysandvalues: kciinputimagekey, beginimage, @"inputintensity", [nsnumber numberwithfloat:currentvalue], nil]; //4 ciimage *outputimage = [filter outputimage]; cgimageref cgimg = [context createcgimage:outputimage fromrect:[outputimage extent]]; //5 self.imageview.image = [uiimage imagewithcgimage:cgimg]; //6 cgimagerelease(cgimg); } } - (ibaction)applyeffect:(id)sender { currentbutton=1; }
the problem occurring because don't save original image. change image each time slider changes, effect compounds. here should instead:
in @interface
:
@property(strong, nonatomic)uiimage *originalimage;
in @implementation
:
-(void)viewdidload{ [super viewdidload]; self.imageview.image = self.originalimage; }
then when effect, apply originalimage
property , show result in self.imageview.
Comments
Post a Comment