Swift - 给图片添加图片水印(图片上绘制另一张图,并可设透明度)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
//--- UIImageExtension.swift ---extension UIImage{ //水印位置枚举 enum WaterMarkCorner{ case TopLeft case TopRight case BottomLeft case BottomRight } //添加图片水印方法 func waterMarkedImage(waterMarkImage:UIImage, corner:WaterMarkCorner = .BottomRight, margin:CGPoint = CGPoint(x: 20, y: 20), alpha:CGFloat = 1) -> UIImage{ var markFrame = CGRectMake(0, 0, waterMarkImage.size.width, waterMarkImage.size.height) let imageSize = self.size switch corner{ case .TopLeft: markFrame.origin = margin case .TopRight: markFrame.origin = CGPoint(x: imageSize.width - waterMarkImage.size.width - margin.x, y: margin.y) case .BottomLeft: markFrame.origin = CGPoint(x: margin.x, y: imageSize.height - waterMarkImage.size.height - margin.y) case .BottomRight: markFrame.origin = CGPoint(x: imageSize.width - waterMarkImage.size.width - margin.x, y: imageSize.height - waterMarkImage.size.height - margin.y) } // 开始给图片添加图片 UIGraphicsBeginImageContext(imageSize) self.drawInRect(CGRectMake(0, 0, imageSize.width, imageSize.height)) waterMarkImage.drawInRect(markFrame, blendMode: .Normal, alpha: alpha) let waterMarkedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return waterMarkedImage }} |
3,使用样例
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import UIKitclass ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() //给图片添加水印 imageView.image = UIImage(named:"bg")? .waterMarkedImage(UIImage(named: "logo7")!,corner: .TopLeft, margin: CGPoint(x: 20, y: 20), alpha:1) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }} |
Swift - 给图片添加图片水印(图片上绘制另一张图,并可设透明度)的更多相关文章
- Swift - 给图片添加文字水印(图片上写文字,并可设置位置和样式)
想要给图片添加文字水印或者注释,我们需要实现在UIImage上写字的功能. 1,效果图如下: (在图片左上角和右下角都添加了文字.) 2,为方便使用,我们通过扩展UIImage类来实现添加水印功能 ( ...
- php图片添加文字水印方法汇总
方法一: <?php header("content-type:text/html;charset=utf-8"); //指定图片路径 $src = "img/a. ...
- php给图片添加文字水印方法汇总
在php中要给图片加水印我们需要给php安装GD库了,这里我们不介绍GD库安装,只介绍怎么利用php给图片添加文字水印的4种方法的汇总.有需要的小伙伴可以参考下. 1: 面向过程的编写方法 1 2 3 ...
- php 图片添加文字水印 以及 图片合成(微信快码传播)
1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...
- 利用php给图片添加文字水印--面向对象与面向过程俩种方法的实现
1: 面向过程的编写方法 //指定图片路径 $src = '001.png'; //获取图片信息 $info = getimagesize($src); //获取图片扩展名 $type = image ...
- 一种基于重载的高效c#上图片添加文字图形图片的方法
在做图片监控显示的时候,需要在图片上添加文字,如果用graphics类绘制图片上的字体,实现图像上添加自定义标记,这种方法经验证是可行的,并且在visual c#2005 编程技巧大全上有提到,但是, ...
- C#图片添加文字水印
/// <summary> /// 给图片添加文字水印 /// </summary> /// <param name="img">图片</ ...
- php使用GD库实现图片水印和缩略图——给图片添加文字水印
今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...
- PHP给图片添加文字水印实例
PHP给图片添加文字水印实例,支持中文文字水印,是否覆盖原图,自定义设置水印背景色.文字颜色.字体等. 水印类water.class.php var $Path = "./"; / ...
随机推荐
- The Priest Mathematician
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/F f[0] = 1 , f[ i ] = f[ i - 1 ] ...
- cocos2dx进阶学习之CCDirector
继承关系 CCDirecotor -> CCObject, TypeInfo 处理主窗口消息,管理何时.何种方式执行场景. 经常被翻译成导演,负责管理整个游戏的进程推动和周边支持. 成员 inl ...
- 基于visual Studio2013解决C语言竞赛题之0303最大数
题目 解决代码及点评 这道题考察对条件分支和赋值的灵活应用 正常思维 如果 a>b and a>c 那么a最大 如果b>c and b>a 那么b最大 如果c>a ...
- ALEXANDER WANG 北京旗舰店开业活动
ALEXANDER WANG 北京旗舰店开业活动-搜狐女人 ALEXANDER WANG 北京旗舰店开业活动
- 解决warning: incompatible implicit declaration of built-in function 'malloc'
因为代码中使用了malloc函数和字符串函数.编译时出现错误 warning: incompatible implicit declaration of built-in function 'mall ...
- UINavigationController具体解释(二)
@UINavigationBar-----(是一个View)基本介绍 1.导航栏,和导航控制器一样,是一个容器用来显示提供的其它对象的内容 2.导航栏显示的内容,通过设置UINavigationIte ...
- oracle误删的表恢复
flashback table lip_organization to before drop;
- week4_motion_of_ball_1(小球运动)——最基本
# Ball motion with an explicit timer import simplegui # Initialize globals width = 600 height = 600 ...
- [转] 解析LayoutSubviews
转自: http://www.cnblogs.com/YouXianMing/p/3897543.html 从百度上搜索了一下layoutSubviews的用处,以下是搜索的结果,当然,笔者是会一一验 ...
- 多层TreeWidget可选实现
http://download.csdn.net/detail/lingyunfuyu2/9117481