I have this new iOS 8 Swift project and in one of its view controllers I have to set the image. However, I wanna change the contrast of the image using CIFilter
before sending it to the view:
So this is my code:
view = UIImageView(frame:CGRectMake(0, 0, 200, 200))
var lecturePicture = UIImage(named: "placeholder")
var beginImage = lecturePicture?.CIImage
var controlsFilter = CIFilter(name: "CIColorControls")
controlsFilter.setValue(beginImage, forKey: kCIInputImageKey)
controlsFilter.setValue(1.5, forKey: "inputContrast")
var displayImage = UIImage(CIImage: controlsFilter.outputImage) // breakpoint
(view as UIImageView!).image = displayImage
Well, I'm simply getting an image, applying a transformation to it and then get the transformed version as a UIImage
and setting it back to my view.
But I only get an error:
fatal error: unexpectedly found nil while unwrapping an Optional value
Can someone please tell me what am I doing wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…