zoukankan      html  css  js  c++  java
  • 加水印

    复制代码
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIImage *image = [self drawImageAtImageContext];
        UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
        imageView.center = CGPointMake(160, 282);
        [self.view addSubview:imageView];
        
    }
    //添加水印
    -(UIImage *)drawImageAtImageContext{
        //获得一个位图图形上下文
        CGSize size = CGSizeMake(300, 188);//画布大小
        
        UIGraphicsBeginImageContext(size);
        
        UIImage *image = [UIImage imageNamed:@"frame_shop_lovely_bg@2x.jpg"];
        //注意绘图的位置是相对于画布顶点而言,不是屏幕
        [image drawInRect:CGRectMake(0, 0, 300, 188)];
        //添加水印
        CGContextRef ref = UIGraphicsGetCurrentContext();
        //字符的长度和 font
        UIFont *font = [UIFont systemFontOfSize:15];
        NSString *str = @"大金毛";
        int strLength = str.length *font.pointSize;
        //两点确定一条直线
        //下划线的长度等于字符长度
        CGContextMoveToPoint(ref, 200, 178);
        CGContextAddLineToPoint(ref, strLength + 200, 178);
        //直线的颜色、宽度
        [[UIColor redColor]setStroke];
        CGContextSetLineWidth(ref, 2);
        //绘制图像到指定图形上下文,只有边框
        CGContextDrawPath(ref, kCGPathStroke);
        //字符的位置
        [str drawInRect:CGRectMake(200, 158, 100, 30) withAttributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor redColor]}];
        //返回绘制的新图形
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        //最后一定不要忘了关闭上下文
        UIGraphicsEndImageContext();
        
        return newImage;
    }
  • 相关阅读:
    用Java画QRCode二维码
    Require.js 详细了解
    JAVA下几个问题
    Eclipse中使用Maven创建Web时错误
    Windows下MySQL安装配置与使用
    搭建 LimeSurvey投票调查问卷系统
    服务器常见页面访问返回错误信息
    linux系统使用python监测网络接口获取网络的输入输出
    Linux操作系统知识
    lvs工作原理
  • 原文地址:https://www.cnblogs.com/cdp-snail/p/5519334.html
Copyright © 2011-2022 走看看