IOS给图片加水印

/**
 *  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;
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。