Combining 2 UIImage to create a new UIImage in WatchKit

I want to overlay one UIImage onto another to create a 3rd UIImage (think of it as a logo chosen at runtime placed on a background image) I will be using this combined UIImage as a material in SceneKit.

I've seen that it can be done on iOS using UIImageView, but that doesn't exist in WatchKit. Is there are way to do this in WatchKit? I've looked everywhere and can't find anything useful.

Post the code to do it with a UIImageView, and we might be able to convert it to something available in WatchKit.

Also, are you wanting to do this in SwiftUI, like, using an Image?

I found some sample code for combining UIImages (see below), but cannot use it because is uses UIImageView, which is not in WatchKit (although, it is kinda what I want to do). I am using Swift, not SwiftUI.

let bgimg = UIImage(named: "image-name") // The image used as a background let bgimgview = UIImageView(image: bgimg) // Create the view holding the image bgimgview.frame = CGRect(x: 0, y: 0, width: 500, height: 500) // The size of the background image

let frontimg = UIImage(named: "front-image") // The image in the foreground let frontimgview = UIImageView(image: frontimg) // Create the view holding the image frontimgview.frame = CGRect(x: 150, y: 300, width: 50, height: 50) // The size and position of the front image

bgimgview.addSubview(frontimgview) // Add the front image on top of the background

Found a solution using UIGraphicsBeginImageContext, etc. Gotta adjust for my needs, but it's exactly what I need!

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()

Combining 2 UIImage to create a new UIImage in WatchKit
 
 
Q