zoukankan      html  css  js  c++  java
  • iOS_UIImage_给图片添加水印

    github地址: https://github.com/mancongiOS/UIImage.git

    UIImage的Category

    UIImage+ImageWaterPrint.h

    #import <UIKit/UIKit.h>
    
    @interface UIImage (ImageWaterPrint)
    
    - (UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString *)waterString;
    
    @end

    UIImage+ImageWaterPrint.m

    #import "UIImage+ImageWaterPrint.h"
    
    @implementation UIImage (ImageWaterPrint)
    
    - (UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString *)waterString {
    
        UIGraphicsBeginImageContext(self.size);
        
        // 原始图片渲染
        [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
        
        CGFloat waterX = self.size.width - 200;
        CGFloat waterY = self.size.height - 200;
        CGFloat waterW = 200;
        CGFloat waterH = 200;
        
        // logo 渲染
        [imageLogo drawInRect:CGRectMake(waterX, waterY, waterW, waterH)];
        
        // 渲染文字
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
        
        paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
        
        NSDictionary * dic = @{
                               NSFontAttributeName : [UIFont systemFontOfSize:40],
                               NSParagraphStyleAttributeName : paragraphStyle,
                               NSForegroundColorAttributeName : [UIColor redColor]
                               };
        
        [waterString drawInRect:CGRectMake(50, 50, 200, 50) withAttributes:dic];
        
        UIGraphicsEndPDFContext();
        
        // UIImage
        UIImage * imageNew = UIGraphicsGetImageFromCurrentImageContext();
        
        return imageNew;
    }
    
    @end
  • 相关阅读:
    lamp
    ssh 交互脚本
    mysql 备份检测主从脚本
    RANDOM 猜数字脚本
    ansible+playbook 搭建lnmp环境
    集群搭建
    grafana
    nginx lnmp搭建
    shell 基础(1): 变量
    seq 增量输出命令
  • 原文地址:https://www.cnblogs.com/mancong/p/6138140.html
Copyright © 2011-2022 走看看