iPhone, how does one overlay one image onto another to create a new image to save? (watermark)

前端 未结 5 1193
逝去的感伤
逝去的感伤 2021-01-30 00:13

Basically I want to take an image that the user chooses from their photo library and then apply a watermark, a triangle in the lower right that has the app name on it. I have th

5条回答
  •  梦毁少年i
    2021-01-30 00:52

    SWIFT 5 Function:

    func addWaterMark(image: UIImage) -> UIImage {
            let backgroundImage = image//UIImage(named: "image.png")
            let watermarkImage = UIImage(named: "waterMark.png")
    
            UIGraphicsBeginImageContextWithOptions(backgroundImage.size, false, 0.0)
            backgroundImage.draw(in: CGRect(x: 0.0, y: 0.0, width: backgroundImage.size.width, height: backgroundImage.size.height))
            watermarkImage!.draw(in: CGRect(x: backgroundImage.size.width - watermarkImage!.size.width, y: backgroundImage.size.height - watermarkImage!.size.height, width: watermarkImage!.size.width, height: watermarkImage!.size.height))
            let result = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return result!
        }
    

提交回复
热议问题