如何在SWIFT中将多个图像合并为单个图像(例如DSLR相机中的多重曝光功能)

时间:2019-07-15 13:16:57

标签: swift xcode uiimage avfoundation

我正在开发PhotoEditing应用程序。我想合并多个图像。使用AVFoundation框架捕获图像阵列。现在我要合并这些图像。我尝试了这种方法,但是它没有按照我想要的方式工作,它只是一张一张地追加图像。

let bottomImage = images[0]
let frontImage = images[1]
let size = CGSize(width: 67, height: 55)
UIGraphicsBeginImageContext(size)
let areaSize = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let frontImageSize = CGRect(x: 14, y: 3, width: 40, height: 40)
bottomImage.draw(in: areaSize, blendMode: CGBlendMode.normal, alpha:  1.0)
frontImage.draw(in: frontImageSize, blendMode: CGBlendMode.normal, alpha: 1.0)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

if let imageData = newImage?.pngData() {
    previewView.image = UIImage(data: imageData)
}

0 个答案:

没有答案