例如,我可以拍摄图像A和图像B来创建包含两个图像并排的图像C吗?
答案 0 :(得分:1)
是的。以下代码将两幅图像并排缝合在一起:
// This rect is where your resulting image goes
let resultingRect = CGRect(x: 0, y: 0, width: 200, height: 100)
UIGraphicsBeginImageContextWithOptions(resultingRect.size, false, 1)
let context = UIGraphicsGetCurrentContext()
context?.interpolationQuality = .high
// Drawing left image
let leftImage = UIImage(named: "pikachu.jpg")!
let leftRect = CGRect(x: 0, y: 0, width: 100, height: 100)
leftImage.draw(in: leftRect)
// Drawing right image
let rightImage = UIImage(named: "pikachu.jpg")!
let rightRect = CGRect(x: 100, y: 0, width: 100, height: 100)
rightImage.draw(in: rightRect)
// Get image from current context
let newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageView.image = newImage
当然,您可以尝试很多选项,应该看看,但这是一个很好的起点。