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. 图像处理---《在图片上打印文字 windows+GDI+TrueType字体》

    图像处理---<在图片上打印文字  windows+GDI+TrueType字体> 刚开始使用的是putText()函数做,缺陷是只能显示非中文: 接着,看大多数推荐Freetype库来做 ...

  2. 图像处理---《在图片上打印文字 FreeType库》

    图像处理---<在图片上打印文字 FreeType库> 目的:想在处理之后的图像上打印输出结果.方法: (1)只在图像上打印 数字.字母的话:                1.Mat格式 ...

  3. 图像处理---《在图片上打印文字 putText()》

    图像处理---<在图片上打印文字 putText()> 目的:想在处理之后的图像上打印输出结果. 方法: (1)只在图像上打印 数字.字母的话:                 1.Mat ...

  4. 海报工厂之(一)android 如何给图片添加水印和文字

    在Android中如何给图片添加水印,下面截取了部分核心代码,仅供参考: /**      * 获取图片缩小的图片      * @param src      * @return      */   ...

  5. IOS 给图片添加水印(文字)

    有时候上传图片要加唯一标识,简单的就是添加一个水印.这里水印我们讲文字,可以是当前系统时间.坐标.地理位置等 原理就是把一个字符串写到图片上,并且字(font)的大小由图片大小控制. 以下是封装好的一 ...

  6. ios 拉伸图片和计算文字的大小

    一.拉伸图片 /** * 传入图片的名称,返回一张可拉伸不变形的图片 * * @param imageName 图片名称 * * @return 可拉伸图片 */ + (UIImage *)resiz ...

  7. ios 给图片添加水印

    //第一种添加水印方法 -(UIImage *)watermarkImage:(UIImage *)img withName:(NSString *)name{ NSString* mark = na ...

  8. java后台中处理图片辅助类汇总(上传图片到服务器,从服务器下载图片保存到本地,缩放图片,copy图片,往图片添加水印图片或者文字,生成二维码,删除图片等)

    最近工作中处理小程序宝箱活动,需要java画海报,所以把这块都快百度遍了,记录一下处理的方法,百度博客上面也有不少坑! 获取本地图片路径: String bgPath = Thread.current ...

  9. Android 图片添加水印图片或者文字

    给图片添加水印的基本思路都是载入原图,添加文字或者载入水印图片,保存图片这三个部分 添加水印图片: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

随机推荐

  1. asp.net后台获取路径的各种方法归纳

    asp.net后台获取路径的各种方法归纳   1.Request.CurrentExecutionFilePath    获取当前请求的虚拟路径,不同于 FilePath,差别在于如果请求已在服务器代 ...

  2. [三分]HDOJ 5531 Rebuild

    题意:给n个点,以这n个点为圆心画圆,使得所有的圆与其相邻的圆相切. 求n个圆最小的面积和. 分析:很容易想到确定了其中一个圆的半径之后,其他的圆的半径也能随之确定了. 画一画三个点的和四个点的,会发 ...

  3. 小心!#define max(a,b) a>b?a:b

    今天做oj的时候,定义了两个宏: //wrong code#define max_2(a,b) a>b?a:b #define max_3(a,b,c) (a>b?a:b)>c?(a ...

  4. Project Euler 81:Path sum: two ways 路径和:两个方向

    Path sum: two ways In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom ...

  5. vlc/ffmepg/mplayer/gstreamer/openmax/mpc/ffdshow/directshow

    一些应该学习的开源框架与库用途和差别 一.播放器层次 这个层次上,是直接可以用的软件,已经做完了一切工作,如果我们需要用他们,是不需要写一行代码的,编译通过就可以拿来使用了,对于国内这些山寨公司来说, ...

  6. ReadDirectoryChangesW 监控文件夹 (一个简单的监控示例程序)(文件被修改了,也可以探测到)

    // .h文件 #pragma once typedef void (*PFN_NotifyAction)(DWORD dwAction, LPWSTR szFile, DWORD dwLength) ...

  7. Go语言博客

    http://www.cnblogs.com/concurrency/p/4293613.html#3130523

  8. Android:实现数组之间的复制

    System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制 System.arraycopy(src, srcPos, dst, dstPos, length); src ...

  9. 本人arcgis api for javascript中常见错误总结

    1. 2.对象不支持"replace"属性或方法 解决办法:一般在ie中执行js会报这样的错误,基本问题就是你引用了某个对象中不存在的方法,可能是这个方法本来存在而你写错了,或者调 ...

  10. 247. Strobogrammatic Number II

    题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...