func getWaterMark(_ originalImage: UIImage?, title: String, andMark markFont: UIFont, andMark markColor: UIColor) -> UIImage? {
let HORIZONTAL_SPACE: CGFloat = 30
let VERTICAL_SPACE: CGFloat = 50
var font: UIFont? = markFont
if font == nil {
font = UIFont.systemFont(ofSize: 23)
}
var color: UIColor? = markColor
if color == nil {
color = UIColor.blue
}
//原始image的宽高
guard let viewWidth = originalImage?.size.width, let viewHeight = originalImage?.size.height else { return nil }
//为了防止图片失真,绘制区域宽高和原始图片宽高一样
UIGraphicsBeginImageContext(CGSize(width: viewWidth, height: viewHeight))
//先将原始image绘制上
originalImage?.draw(in: CGRect(x: 0, y: 0, width: viewWidth, height: viewHeight))
//sqrtLength:原始image的对角线length。在水印旋转矩阵中只要矩阵的宽高是原始image的对角线长度,无论旋
Swift 图片加水印
最新推荐文章于 2021-12-10 11:51:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)