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
  • 相关阅读:
    你所不知道的 CSS 阴影技巧与细节
    %date~0,4%和 %time~0,2%等用法详解
    计算程序执行时间
    GDI
    IO
    字符串拼凑批量Insert SQL语句神BUG
    用逗号分隔的数据转换到数组
    MVC ViewBag传值
    接口和抽象类对比
    Partial 同一个命名空间下写两个类名一样的类
  • 原文地址:https://www.cnblogs.com/mancong/p/6138140.html
Copyright © 2011-2022 走看看