Created
January 5, 2015 18:58
-
-
Save ryanmasondavies/6ee4d99d06829659e286 to your computer and use it in GitHub Desktop.
Example of pixellating an image picked from a UIImagePickerController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { | |
@IBOutlet weak var imageView: UIImageView! | |
@IBAction func choosePhoto(sender: UIButton) { | |
let picker = UIImagePickerController() | |
picker.delegate = self | |
picker.sourceType = .SavedPhotosAlbum | |
presentViewController(picker, animated: true, completion: nil) | |
} | |
@IBAction func takePhoto(sender: UIButton) { | |
let picker = UIImagePickerController() | |
picker.delegate = self | |
picker.sourceType = .Camera | |
presentViewController(picker, animated: true, completion: nil) | |
} | |
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { | |
println("\(NSDate.date) Pixellating...") | |
let inputImage = CIImage(CGImage: image.CGImage) | |
let imageSize = inputImage.extent().size | |
let pixellationOptions = [kCIInputImageKey: inputImage, kCIInputScaleKey: max(imageSize.width, imageSize.height) / 50] | |
let pixellation = CIFilter(name: "CIPixellate", withInputParameters: pixellationOptions) | |
let pixellatedImage = pixellation.outputImage | |
imageView.image = UIImage(CIImage: pixellatedImage) | |
println("\(NSDate.date) Done") | |
dismissViewControllerAnimated(true, completion: nil) | |
} | |
func imagePickerControllerDidCancel(picker: UIImagePickerController) { | |
dismissViewControllerAnimated(true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment