我想在我的代码中添加一个很好的功能。 我有一个UIimage(capturePhoto,我在之前的VC上使用了Camera模块)
我想向右/向左滑动并将过滤器更改为我的capturePhoto。
我遇到的问题:使用我的代码(见下文),图像的分辨率会发生变化。我想保留原来的决议。
我的代码:
on viewdidload
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(PreviewController.swiped(gesture:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
然后我有一个功能来检查滑动
func swiped(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
print("User Swiped Right")
case UISwipeGestureRecognizerDirection.left:
print("User Swiped Left")
let inputImage = capturedPhoto!
let context = CIContext(options: nil)
if let currentFilter = CIFilter(name: "CIPhotoEffectNoir") {
let beginImage = CIImage(image: inputImage)
currentFilter.setValue(beginImage, forKey: kCIInputImageKey)
currentFilter.setValue(0.5, forKey: kCIInputIntensityKey)
if let output = currentFilter.outputImage {
if let cgimg = context.createCGImage(output, from: output.extent) {
let processedImage = UIImage(cgImage: cgimg)
// do something interesting with the processed image
self.ImageEdit.image = processedImage
} } }
default:
break
}}}
如果有人可以帮助我:
非常感谢!