//
// TopViewController.swift
//
// Created by Yusuke Sugomori on 9/9/14.
// Copyright (c) 2014 Yusuke Sugomori. All rights reserved.
//
import UIKit
class TopViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
let image = UIImage(named: "test.jpg")
// Core Image context
let ciContext = CIContext(options: nil)
// CIImage, think of a CIImage as image data for processing, nothing is displayed or can be displayed at this point
let coreImage = CIImage(image: image)
// pick the filter
let filter = CIFilter(name: "CIPhotoEffectTransfer")
// pass image as input
filter.setValue(coreImage, forKey: kCIInputImageKey)
// retrieve the processed image
let filteredImageData = filter.valueForKey(kCIOutputImageKey) as CIImage
// returns a Quartz image from the Core Image context
let filteredImageRef = ciContext.createCGImage(filteredImageData, fromRect: filteredImageData.extent())
// final UIImage ready to be displayed
let filteredImage = UIImage(CGImage: filteredImageRef)
let imageView = UIImageView(image: filteredImage)
imageView.frame = CGRectMake(0, 0, screenWidth, screenHeight)
imageView.contentMode = UIViewContentMode.ScaleAspectFit
self.view.addSubview(imageView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme