gpt4 book ai didi

ios - 如何使用 Swift 将模糊效果添加到 UIImage 中?

转载 作者:行者123 更新时间:2023-11-28 06:24:27 25 4
gpt4 key购买 nike

<分区>

我想在 UIimage 中添加模糊效果,而不是 UIImage View。我可以将模糊效果添加到 uiimage View 中就像这样:

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = img.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
img.addSubview(blurEffectView)

但是,我真的很想添加到 uiimage 中。因为我必须用文字绘制图像。所以这是我的功能:

func textToImageWithPhoto(drawText text: NSString, inImage image: UIImage, atPoint point: CGPoint) -> UIImage {  

let scale = UIScreen.main.scale

UIGraphicsBeginImageContextWithOptions(CGSize.init(width: 375, height: 375), false, scale)

image.draw(in: CGRect(origin: CGPoint.init(x: 0, y: -100), size: CGSize(width: 375, height: 375*1.5)))

let rect = CGRect(origin: CGPoint.init(x: 0, y: 187.5 - 150/2 ), size: CGSize.init(width: 375, height: 375))
text.draw(in: rect, withAttributes: textFontAttributes)

let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

self.saveData(img: newImage!, text: self.quotesTxt.text!) //SAVE CORE DATA

return newImage!
}

有什么方法可以在绘图函数中添加模糊效果吗?

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