1.加文字

 
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1 
{     
     //get image width and height     
     int w = img.size.width;    
     int h = img.size.height;     
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();     
    //create a graphic context with CGBitmapContextCreate     
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);    
    CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);     
    CGContextSetRGBFillColor(context, 0.0, 1.0, 1.0, 1);     
    char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];     
    CGContextSelectFont(context, "Georgia", 30, kCGEncodingMacRoman);     
    CGContextSetTextDrawingMode(context, kCGTextFill);     
    CGContextSetRGBFillColor(context, 255, 0, 0, 1);     
    CGContextShowTextAtPoint(context, w/2-strlen(text)*5, h/2, text, strlen(text));     
    //Create image ref from the context     
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);     
    CGContextRelease(context);     
    CGColorSpaceRelease(colorSpace);     
    return [UIImage imageWithCGImage:imageMasked]; 
}
 
2.加图片
-(UIImage *)addImageLogo:(UIImage *)img text:(UIImage *)logo 
{    
    //get image width and height     
    int w = img.size.width;     
    int h = img.size.height;    
    int logoWidth = logo.size.width;     
    int logoHeight = logo.size.height;     
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();           
    //create a graphic context with CGBitmapContextCreate     
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);     
    CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);     
    CGContextDrawImage(context, CGRectMake(w-logoWidth, 0, logoWidth, logoHeight), [logo CGImage]);     
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);     
    CGContextRelease(context);     
    CGColorSpaceRelease(colorSpace);     
    return [UIImage imageWithCGImage:imageMasked];     
    //  CGContextDrawImage(contextRef, CGRectMake(100, 50, 200, 80), [smallImg CGImage]); 
}
 
3.加半透明的水印
- (UIImage *)addImage:(UIImage *)useImage addImage1:(UIImage *)addImage1
{       
    UIGraphicsBeginImageContext(useImage.size);            
    [useImage drawInRect:CGRectMake(0, 0, useImage.size.width, useImage.size.height)];          
    [addImage1 drawInRect:CGRectMake(0, useImage.size.height-addImage1.size.height, addImage1.size.width, addImage1.size.height)];         
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();      
    UIGraphicsEndImageContext();           
    return resultingImage;   
}

ios 加水印的更多相关文章

  1. iOS图片加水印效果的实现并保存至相冊

    图片加水印效果的实现并保存至相冊 实现效果如图: project下载:githubproject下载链接 代码: - (void)viewDidLoad { [super viewDidLoad]; ...

  2. Python练习册--PIL处理图片之加水印

    背景 最近在看到了Python 练习册,每天一个小程序 这个项目,非常有趣,也比较实用. 晚上看了这第000题,关于Python图片处理: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似 ...

  3. 火车头dede采集接口,图片加水印,远程图片本地化,远程无后缀的无图片本地化

    <?php /* [LocoySpider] (C)2005-2010 Lewell Inc. 火车采集器 DedeCMS 5.7 UTF8 文章发布接口 Update content: 图片加 ...

  4. thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印

    今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...

  5. 【转】WPF TextBox和PasswordBox加水印

    Textbox加水印 Textbox加水印,需要一个VisualBrush和触发器验证Text是否为空,在空的时候设置背景的Brush就可以实现水印效果. <TextBox Name=" ...

  6. Web 上传图片加水印

    上传图片加水印 需要使用控件FileUpload 上传按钮Image控件展示上传的图片,页面中拖入三个控件 <form id="form1" runat="serv ...

  7. PHPThumb处理图片,生成缩略图,图片尺寸调整,图片截取,图片加水印,图片旋转

    [强烈推荐]下载地址(github.com/masterexploder/PHPThumb). 注意这个类库有一个重名的叫phpThumb,只是大小写的差别,所以查找文档的时候千万注意. 在网站建设过 ...

  8. 使用iText对pdf做权限的操作(不允许修改,不允许复制,不允许另存为),并且加水印等

    添加水印,并且增加权限 @Test public void addWaterMark() throws Exception{ String srcFile="D:\\work\\pdf\\w ...

  9. 用node.js给图片加水印

    一.准备工作: 首先,确保你本地已经安装好了node环境.然后,我们进行图像编辑操作需要用到一个Node.js的库:images.这个库的地址是:https://github.com/zhangyua ...

随机推荐

  1. css黑魔法

    多行文本溢出显示省略号(...)的方法 p { overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-li ...

  2. Tomcat7配置数据源(Oracle)

    修改../conf/content.xml <?xml version='1.0' encoding='utf-8'?> <!-- The contents of this file ...

  3. 项目中经常用到的reset.css文件

    html,body{width:100%; height: auto;} *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box- ...

  4. Algorithms 4th - 1.1 Basic Programming Model - EXERCISES

    欢迎交流 1.1.1 a. 7 b. 200.0000002 c. true 1.1.2 a. 1.618 b. 10.0 c. true d. 33 1.1.3 public class MainA ...

  5. leetcode Remove Element python

    class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] ...

  6. jQuery on()方法绑定动态元素的点击事件无效

    之前就一直受这个问题的困扰,在jQuery1.7版本之后添加了on方法,之前就了解过,其优越性高于live(),bind(),delegate()等方法,在此之前项目中想用这个来测试结果发现,居然动态 ...

  7. Android Studio 添加Assets目录

    Android Studio 添加Assets目录: 法一: Since Android Studio uses the new Gradle-based build system, you shou ...

  8. objective -c 知識点

    那么类别与继承相比,有什么缺点吗?类别不可以声明新的成员变量,而且一旦你定义的方法与原始类中的方法名称相同,那么原始方法将被隐藏起来,因为不是继承结构,你不能在类别中的方法使用super 激活原始类的 ...

  9. js屏蔽浏览器(IE和FireFox)的刷新和右键等功能

    //一.js屏蔽浏览器(IE和FireFox)的刷新功能 document.onkeydown=function() { if ((window.event.keyCode==116)|| //屏蔽 ...

  10. struts中简单的校验

    Struts中简单的校验 “计应134(实验班) 凌豪” Struts2校验简要说明:struts2中通常情况下,类型转换要在数据校验之前进行.类型转换其实也是基本的服务器端校验,合法数据必然可以通过 ...