Hello I am developing the application which requires to merge two Image , My image size are 320*240 by merging both Image I want the size to be 320 * 480 . How can i do this
This implementation works for variadic arguments, so you can pass an unlimited number of images to merge vertically:
public static func mergeVertically(images: UIImage...) -> UIImage? {
let maxWidth = images.reduce(0.0) { max($0, $1.size.width) }
let totalHeight = images.reduce(0.0) { $0 + $1.size.height }
UIGraphicsBeginImageContextWithOptions(CGSize(width: maxWidth, height: totalHeight), false, 0.0)
defer {
UIGraphicsEndImageContext()
}
let _ = images.reduce(CGFloat(0.0)) {
$1.draw(in: CGRect(origin: CGPoint(x: 0.0, y: $0), size: $1.size))
return $0 + $1.size.height
}
return UIGraphicsGetImageFromCurrentImageContext()
}