gpt4 book ai didi

ios - 合成两个 CIImages 并在 UIImageView 问题中显示

转载 作者:行者123 更新时间:2023-11-28 15:09:42 34 4
gpt4 key购买 nike

<分区>

我在使用 CIFilter 将两个图像组合在一起时遇到了问题。这里出了什么问题?

下面的代码创建了一个 UIImageView 并将其添加到 View 中,然后将两个图像 imageAimageBCIFilter 组合在一起,并将合成输出到 UIImageView

但是,合并后的图像没有显示在 UIImageView 中,它仍然是空白。


Questions:

  1. What is the correct code to display the composite image into the UIImageView?
  2. Is there more performant way in which to combine two images with CIFilter?

代码:

    let imageView = UIImageView()
imageView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
imageView.contentMode = .Center
view.addSubview(imageView)

let imageA = CIImage(image: UIImage(named:"imageA")!)
let imageB = CIImage(image: UIImage(named:"imageB")!)
let imageFilter = CIFilter(name: "CIAdditionCompositing")!

imageFilter.setValue(imageA, forKey: kCIInputImageKey)
imageFilter.setValue(imageB, forKey: kCIInputBackgroundImageKey)

if let imageCombined = imageFilter.outputImage {
let image = UIImage(CIImage: imageCombined)
imageView.image = image
}

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com