画像の合成 Swift3
説明
実装
import UIKit
class ViewController: UIViewController {
let imageView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
let topImage:UIImage = UIImage(named:"topImage")!
let bottomImage:UIImage = UIImage(named: "bottomImage")!
let newSize = CGSize(width:bottomImage.size.width, height:bottomImage.size.height)
UIGraphicsBeginImageContextWithOptions(newSize, false, bottomImage.scale)
bottomImage.draw(in: CGRect(x:0,y:0,width:newSize.width,height:newSize.height))
topImage.draw(in: CGRect(x:0,y:0,width:newSize.width,height:newSize.height),blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
let screenWidth:CGFloat = view.frame.size.width
let screenHeight:CGFloat = view.frame.size.height
imageView.image = newImage
let newRect = CGRect(x:0, y:0, width:200, height:200)
imageView.frame = newRect
imageView.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
self.view.addSubview(imageView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}