How to merge two UIImages?

后端 未结 7 1603
野趣味
野趣味 2020-12-07 16:57

I am trying to merge two different images and create a new one. This is the way I would like to do: I have this image (A):

It\'s a PNG image and I would like to mer

7条回答
  •  不思量自难忘°
    2020-12-07 17:10

    Hope this may help you,

    var bottomImage = UIImage(named: "bottom.png")
    var topImage = UIImage(named: "top.png")
    
    var size = CGSize(width: 300, height: 300)
    UIGraphicsBeginImageContext(size)
    
    let areaSize = CGRect(x: 0, y: 0, width: size.width, height: size.height)
    bottomImage!.draw(in: areaSize)
    
    topImage!.draw(in: areaSize, blendMode: .normal, alpha: 0.8)
    
    var newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    

    All the Best :)

提交回复
热议问题