ios - CGRect 在 Swift 中改变原点
问题描述
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
))
...
在这种情况下更改原点是可能的,但不切实际。
推荐阅读
- python-3.x - 从 Python 的一列中替换和删除重复的字符串元素
- android - Google Play 控制台 - 内部测试链接不起作用
- c - 如果内存未分配给字符串,则 CS50.h 分段错误
- javascript - 映射函数不适用于扩展数组的类
- javascript - 如何找到javascript在asp文件中的开始和结束位置?
- multithreading - 如何在 AMD 处理器(32 核)和 Windows 10 Pro 上调用 SAS Base(https://www.sas.com/)中的多线程?
- redis - Spring Reactive Redis:如果发布者或订阅者不在同一台机器上运行,则 PubSub 不起作用
- php - 通过 URL 从插件运行函数
- python - 如何重新排序 CSV 文件的行?
- rest - 如何使用javascript从获取请求中显示网页