码迷,mamicode.com
首页 > 移动开发 > 详细

IOS给图片加水印

时间:2015-01-15 21:53:33      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

/**
 *  imageWithBackgroundImage::
 *
 *  @param backgroundImage 背景图片名
 *  @param logoImage       水印图片名
 *
 *  @return 加上水印后的图片
 */
+ (instancetype)imageWithBackgroundImage:(NSString *)backgroundImage withLogoImage:(NSString *)logoImage
{
    UIImage *image = [UIImage imageNamed:backgroundImage];
    
    //1.开启一个基于位图bitmap上下文
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
    
    //2.画背景
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    
    //3.画水印
    //3.1设置水印图片frame
    UIImage *log = [UIImage imageNamed:logoImage];
    CGFloat margin = 5.0;
    CGFloat scale = 0.2;
    CGFloat logoW = log.size.width * scale;
    CGFloat logoH = log.size.height * scale;
    CGFloat logoX = image.size.width - logoW - margin;
    CGFloat logoY = image.size.height - logoH - margin;
    //3.2画水印
    [log drawInRect:CGRectMake(logoX, logoY, logoW, logoH)];
    
    //4.从图形上下文取出图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
   
    return newImage;
}

 

IOS给图片加水印

标签:

原文地址:http://www.cnblogs.com/canghaige/p/4227236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!