zoukankan      html  css  js  c++  java
  • iOS在照片上添加水印

    在做项目的时候我们需要将拍摄的照片做上标记防止图片被他人盗用,所以这就需要在照片的上面加上水印,以表示此照片的独一无二。

    加水印不是要在上面添加上几个Label,而是我们要把字画到图片上成为一个整体。

    提供一个方法 此方法只需要传递一个要加水印的图片和水印的内容就达到效果

     1 -(UIImage *)watermarkImage:(UIImage *)img withName:(NSString *)name
     2 
     3 {
     4 
     5     NSString* mark = name;
     6 
     7     int w = img.size.width;
     8 
     9     int h = img.size.height;
    10 
    11     UIGraphicsBeginImageContext(img.size);
    12 
    13     [img drawInRect:CGRectMake(0, 0, w, h)];
    14 
    15     NSDictionary *attr = @{
    16 
    17                            NSFontAttributeName: [UIFont boldSystemFontOfSize:20],   //设置字体
    18 
    19                            NSForegroundColorAttributeName : [UIColor redColor]      //设置字体颜色
    20 
    21                            };
    22 
    23     [mark drawInRect:CGRectMake(0, 10, 80, 32) withAttributes:attr];                 //左上角
    24 
    25     [mark drawInRect:CGRectMake(w - 80, 10, 80, 32) withAttributes:attr];            //右上角
    26 
    27     [mark drawInRect:CGRectMake(w - 80, h - 32 - 10, 80, 32) withAttributes:attr];   //右下角
    28 
    29     [mark drawInRect:CGRectMake(0, h - 32 - 10, 80, 32) withAttributes:attr];        //左下角
    30 
    31     UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
    32 
    33     UIGraphicsEndImageContext();
    34 
    35     return aimg;
    36 
    37 }

     

  • 相关阅读:
    【linux】驱动-5-驱动框架分层分离&实战
    【linux】驱动-4-LED芯片手册分析
    【MCU】国民N32固件库移植
    【MCU】移植AT32库&FreeRTOS教程
    P3768 简单的数学题
    P4301 [CQOI2013] 新Nim游戏
    P4767 [IOI2000]邮局
    P3211 [HNOI2011]XOR和路径
    FWT 笔记
    P3175 [HAOI2015]按位或(max-min 容斥)
  • 原文地址:https://www.cnblogs.com/sunjiachen/p/4703918.html
Copyright © 2011-2022 走看看