我怎样才能在swift中做到这一点?
我试图将此效果特别设置为图像上的位置。 请提供简单的代码来应用此效果。 提前谢谢。
答案 0 :(得分:0)
试试这段代码:
public typealias Filter = CIImage -> CIImage
public typealias CIParameters = Dictionary<String, AnyObject>
public func bumpDistortion(center: CGPoint, radius: Float, scale: Float) -> Filter {
return { image in
let parameters : CIParameters = [
kCIInputRadiusKey:radius,
kCIInputCenterKey:CIVector(CGPoint:center),
kCIInputScaleKey:scale,
kCIInputImageKey: image]
let filter = CIFilter(name:"CIBumpDistortion", withInputParameters:parameters)
return filter!.outputImage!
}
}
答案 1 :(得分:0)
让我们假设您使用TastyCat中的代码:
if let image = UIImage(named: "YOUR_IMAGE_NAME") {
let bumpEffect = self.bumpDistortion(YOUR_POINT , radius:YOUR_RADIUS, scale:YOUR_SCALE)
guard let yourCIImage = CIImage(image: image) else {
//handle error
return
}
let result = bumpEffect(yourCIImage)
let theImageWithEffect = UIImage(CIImage:result)
}