Merge Two Image on to one Image programmatically in iphone

前端 未结 10 830
旧巷少年郎
旧巷少年郎 2020-12-04 17:01

Hello I am developing the application which requires to merge two Image , My image size are 320*240 by merging both Image I want the size to be 320 * 480 . How can i do this

10条回答
  •  心在旅途
    2020-12-04 17:46

    //ADDED Swift 3.2 and 4.0

    @IBOutlet weak var imgCamera1: UIImageView!
    @IBOutlet weak var imgCamera2: UIImageView!
    
        let image1 = imgCamera1.image
        let image2 = imgCamera2.image
    
        let size = CGSize(width: image1?.size.width ?? 0.0, height: (image1?.size.height)! + (image2?.size.height)!)
        UIGraphicsBeginImageContext(size)
        image1?.draw(in: CGRect(x: 0, y: 0, width: size.width, height: image1?.size.height ?? 0.0))
        image2?.draw(in: CGRect(x: 0, y: image1?.size.height ?? 0.0, width: size.width, height: image2?.size.height ?? 0.0))
    
        let finalImage = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
    
        //Add image to view
        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: finalImage?.size.width ?? 0.0, height: finalImage?.size.height ?? 0.0))
        imageView.image = finalImage
    
        //Displaying Image
       // view.addSubview(imageView)
    

提交回复
热议问题