been working on swift for a bit now and having trouble tackling this Core Image Framework. I was able to successfully create a CIFilter over an image however I'm not sure how to delete it. The Image Is placed over a UIView which resembles that of snapchat's camera screen and then there is an imageview which is a subview of the uiview that the image is previewed on. BTW Using The most up to date version of Xcode and iOS as well.
Here is the code for when the black and white filter is applied:
@IBAction func BW_Flt_Bt_Tapped(sender: UIButton) {
let beginImage = CIImage(image: imagePreview.image!)
let ciContext = CIContext(options: nil)
let filter = CIFilter(name: "CIPhotoEffectNoir")
var imgOrientation = imagePreview.image!.imageOrientation
var imgScale = imagePreview.image?.scale
filter!.setDefaults()
filter!.setValue(beginImage, forKey: kCIInputImageKey)
let filteredImageData = filter!.valueForKey(kCIOutputImageKey) as! CIImage
let filteredImageRef = ciContext.createCGImage(filteredImageData, fromRect: filteredImageData.extent)
imagePreview.image = UIImage(CGImage: filteredImageRef, scale: 1.0, orientation: UIImageOrientation.Right)
self.orgImgBt.hidden = false
self.orgImgL.hidden = false
BWFlt.hidden = true
BWLbl.hidden = true
}
-imagePreview is the subview of the UIView
Next is my code for how to change the image back
@IBAction func orgImgPressed(sender: UIButton) {
self.imagePreview.image = self.selctedImage
orgImgBt.hidden = true
orgImgL.hidden = true
`enter code here` BWFlt.hidden = false
`enter code here`BWLbl.hidden = false
print("button was pressed")
}
If anyone had any suggestions I would be very appreciative, Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…