From e43bd28aaad8f3e6b24ee8710225c4568b010337 Mon Sep 17 00:00:00 2001 From: Zhihai Zhu <> Date: Sat, 20 Apr 2024 22:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=83=BD=E5=A4=9F=E8=B0=83?= =?UTF-8?q?=E8=8A=82=E7=9E=B3=E8=B7=9D=E7=9A=84=E5=85=B3=E9=94=AE=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Util/PlayByTransferConvertor.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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 )