实现能够调节瞳距的关键步骤
This commit is contained in:
parent
8c4ad06daa
commit
e43bd28aaa
@ -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 )
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user