https://drive.google.com/file/d/1Nd6q9OmDppJrxjZIRODzffVDiBXKnB_e/view?usp=sharing
我想改变“原点”的位置,就像一张用来合成水印的图片。
下面是我的代码。
var watermark = UIImage(named: "logo.png")
var newHeight = filteredImage.image?.size.height
var newWidth = filteredImage.image?.size.width
UIGraphicsBeginImageContext(CGSize(width:newWidth!, height:newHeight!))
watermark.draw(in: CGRect(x:-0, y:-0, width:400, height:300))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
watermark = newImage!
filter = CIFilter(name: "CISourceOverCompositing")
filter!.setValue(CIImage(image: watermark), forKey: "inputImage")
filter!.setValue(coreImage1, forKey: "inputBackgroundImage")
我该如何更改代码?
最佳答案
如果要将水印置于右下角,请使用:
var watermark = UIImage(named: "logo.png")!
var newSize = filteredImage.image.size
UIGraphicsBeginImageContext(newSize)
watermark.draw(in: CGRect(
x: newSize.width - watermark.image.width,
y: newSize.height - watermark.image.height,
width: watermark.image.width,
height: watermark.image.height
))
...
改变原点是可能的,但在这种情况下是不切实际的。