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 = "./"; / ...
随机推荐
- 51cto运维培训课程
线路图: Linux运维架构师 基础提高篇(120课时) 基础提高篇(240课时) Linux系统基础及系统管理 Shell编程入门及进阶 linux安全管理和企业级安全防范策略 企业级集群/存储专题 ...
- gpg-agent具体配置
gpg(gnupg)工具使用很广泛,在前面一篇文章中就具体介绍:http://blog.csdn.net/dongtingzhizi/article/details/26362205,有一个问题值得关 ...
- Android GPS应用:临近警告
前面介绍过LocationManager有一个addProximityAlert(double latitude,double longitude,float radius,long expirati ...
- ThinkPHP - 自定义扩展类库
首先在想要使用类库的地方建立文件夹,文件名称随意,不能使用class 然后在配置文件中: 'AUTOLOAD_NAMESPACE' => array( 'Lib' => './Lib', ...
- ThinkPHP - 博客获取列表信息
得到数据: Array ( [0] => Array ( [id] => 5 [name] => PHP [pid] => 0 [sort] => 1 [blog] =& ...
- AS3清空数组的四种方法
第一种最简单的方法是: var arr:Array = ["a", "b", "c", "d", "e&quo ...
- K - K.Bro Sorting
Description Matt’s friend K.Bro is an ACMer. Yesterday, K.Bro learnt an algorithm: Bubble sort. Bubb ...
- web.xml 中<taglib>报错(转载)
在web.xml加入taglib <taglib> <taglib-uri>/WEB-INF/tiles.tld</taglib- uri> <taglib- ...
- Acitivity的一些属性配置
转自:http://blog.csdn.net/javayinjaibo/article/details/8855678 1.android:allowTaskReparenting 这个属性用来标记 ...
- Android中EditText,Button等控件的设置
EditText可以使用:TextView.setEnabled(true)来设置为可编辑,其实很简单,写在这里以便以后自己查看. Button设置可用性:setVisibility(View.VIS ...