首页 > 代码库 > IOS给图片加水印

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

 

IOS给图片加水印