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")
我应该如何更改代码?
答案 0 :(得分:1)
如果要将水印放置在右下角,请使用:
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
))
...
可以更改原点,但在这种情况下不可行。