Swift 中的 CGRect 更改原点

CGRect change origin in Swift

https://drive.google.com/file/d/1Nd6q9OmDppJrxjZIRODzffVDiBXKnB_e/view?usp=sharing

我想把'origin'的位置改成图片的位置来加水印

下面是我的代码。

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
))

...

可以更改原点,但在这种情况下不切实际。