diff --git a/SwiftProject/SwiftProject/Project/Util/PlayByTransferConvertor.swift b/SwiftProject/SwiftProject/Project/Util/PlayByTransferConvertor.swift index cf49fd9..eaf23ec 100644 --- a/SwiftProject/SwiftProject/Project/Util/PlayByTransferConvertor.swift +++ b/SwiftProject/SwiftProject/Project/Util/PlayByTransferConvertor.swift @@ -176,6 +176,41 @@ class PlayByTransferConvertor { //将两张图片合成一张图片 func joinImages( leftImage:CIImage, rightImage:CIImage) -> CIImage { + let scale = 0.7//此处必须大于0.5 + + let left = UIImage(ciImage: leftImage ) + let right = UIImage(ciImage: rightImage ) + + let imageWidth = left.size.width/2 + let imageHeight = left.size.height + + let n_left = getImgWithScale(image: left, scale: scale - 0.5) + let n_right = getImgWithScale(image: right, scale: scale - 0.5) + + + let newImageSize = left.size //CGSize(width:imageWidth, height: left.size.height); + UIGraphicsBeginImageContextWithOptions(newImageSize, false, 1); + n_left.draw(in: CGRect(x:0, y:0, width:imageWidth, height:imageHeight)) + n_right.draw(in: CGRect(x:imageWidth, y:0, width:imageWidth, height:imageHeight)) + let image = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext(); + + let ci = CIImage(cgImage: image.cgImage!) + return ci + } + + func getImgWithScale(image:UIImage,scale:CGFloat) -> UIImage { + let dRect = CGSizeMake(image.size.width*0.5, image.size.height) + let imgWidth = image.size.width*scale + let imgHeight = image.size.height*scale + UIGraphicsBeginImageContextWithOptions(dRect, false, 1); + image.draw(in: CGRectMake((dRect.width - imgWidth)*0.5, (dRect.height - imgHeight)*0.5, imgWidth, imgHeight)) + let newImage = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext(); + return newImage + } + + func joinImages_backup( leftImage:CIImage, rightImage:CIImage) -> CIImage { let left = UIImage(ciImage: leftImage ) let right = UIImage(ciImage: rightImage )