我四处寻找解决方案,但没有找到。 实际上我有一段代码将 2 个图像合并为一个。 就像我拍一张照片并在上面应用 .png 一样。
但是我想让用户移动顶部图像以便在保存图像之前选择位置
感谢您对我如何做到这一点的任何可能帮助
这是我的功能:
func mergeFrame(bottomImage: UIImage, topImage: UIImage) -> UIImage{
let size = CGSize(width: bottomImage.size.width, height: bottomImage.size.height)
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)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
最佳答案
如果需要移动顶部图像,顶部图像应该有一个灵活的绘图区域。
topImage.draw(in: topArea, BlendMode: .normal, alpha: 0.8)
然后使用 UIPanGesture 在 State.Changed 期间根据gesture.translation 更改 topAread.origin。
在手势的State.End中,调用posted mergeFrame(::)来获取合成图像。
希望你明白了。
关于ios - 合并并编辑2个UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53145400/