Saving an image on top of another image in Swift

前端 未结 4 1870
终归单人心
终归单人心 2020-12-09 11:24

I am learning Swift and I am creating an app that uses a personal photo and puts another on top of it. I now have a hacky solution, to create a screenshot of the area and sa

4条回答
  •  庸人自扰
    2020-12-09 12:25

    Apple advises against UIGraphicsBeginImageContext, so as long as your app supports devices older than iOS 10, then use something like this:

    private func drawLogoIn(_ image: UIImage, _ logo: UIImage, position: CGPoint) -> UIImage {
        let renderer = UIGraphicsImageRenderer(size: image.size)
        return renderer.image { context in
            image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))
            logo.draw(in: CGRect(origin: position, size: logo.size))
        }
    }
    

    Besides performance gains, you get full P3 range.

提交回复
热议问题