Print image on top of imagePicker when taking photo (swift4)

Right now my code does a two step process to print a image Over the current image. Take Image and save image to imageView. Then via another button its print the image over the imageView. How can I do all of this in 1 button not 2.

                              @IBAction func takePhoto(_ sender: UIButton) {
imagePicker =  UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
imagePicker.cameraOverlayView = mainView

 @IBAction func Mask(_ sender: Any) {
let bottomImage:UIImage = UIImage(named: "backdropd")!

let heart:UIImage = UIImage(named: "edit")!

let newSize = CGSize(width: bottomImage.size.width, height: bottomImage.size.height  )
let newSize2 = CGSize(width: bottomImage.size.width, height: bottomImage.size.height)
UIGraphicsBeginImageContextWithOptions(newSize, false, bottomImage.scale)
let left:UIImage = imageTake.image!

left.draw(in: CGRect(x: newSize2.width/5,y: newSize2.height/5,width: newSize2.width/2,height:   newSize2.height/5), blendMode:CGBlendMode.normal, alpha:1.0)

heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height:   newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)

let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!

imageTake.image = newImage


Hi there! Why don’t you implement both steps in the same IBAction (not quite sure from your code what’s actually stopping you from doing just that after all but I may be wrong and missing something over here though)? Cheers! :]

This topic was automatically closed after 166 days. New replies are no longer allowed.