How can I add a watermark to an image using this code?

前端 未结 2 1952
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 16:44

I know there are several other ways to do this; I don\'t want to import anything that I don\'t need to. If someone can help me with his code, that would be great.

Cu

2条回答
  •  一个人的身影
    2020-12-29 17:14

    SWIFT 4 Use this

    let backgroundImage = imageData!
    let watermarkImage = #imageLiteral(resourceName: "jodi_url_icon")
    
    let size = backgroundImage.size
    let scale = backgroundImage.scale
    
    UIGraphicsBeginImageContextWithOptions(size, false, scale)
    backgroundImage.draw(in: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
    watermarkImage.draw(in: CGRect(x: 10, y: 10, width: size.width, height: size.height - 40))
    
    let result = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    

    Use result to UIImageView, tested.

提交回复
热议问题