I'd like to do what this guy was trying to do but in SwiftUI. How can I convert the code in the answers to apply it to SwiftUI?
This is what I have tried so far:
struct ImageMerger {
func merge(_ bottomImageName: String, with topImageName: String) -> UIImage {
let bottomImage = UIImage(named: bottomImageName)
let topImage = UIImage(named: topImageName)
let size = CGSize(width: 375, height: 245)
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: 1)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}}
And to apply it to my view I did the following:
struct Test: View {
var imageMerger = ImageMerger()
var body: some View {
Image(uiImage: imageMerger.merge("Consulta-Dep", with: "CellBackground"))
}}
I switched the bottom image with the top image so you could see that the images aren't changing sizes. This is what it looks like in the Preview: