문제

I have a slider with value. When I change the slider I want the image in imageview to become gray scaled based on the value set in slider.

도움이 되었습니까?

해결책

Firstly you would need to set the image as a property in the view controller, to say myImage for this example.

You also need to create a value changed action for the slider.

Inside the UISlider value changed method, you could use the following:

float sliderValue = VALUE OF SLIDER BETWEEN 0.0 AND 1.0

self.myImage = [UIImage imageWithCGImage:[CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:sliderValue], @"inputColor", [[CIColor alloc] initWithColor:[UIColor whiteColor]], nil].outputImage];

This changes the level of monochrome depending on the slider value.

Which uses the CIFilter class: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIFilter_Class/Reference/Reference.html#//apple_ref/occ/clm/CIFilter/filterWithName:keysAndValues:

And the monochrome filter: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIColorMonochrome

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top