• 给图片画文字


    - (UIImage *)createShareImage:(NSString *)imageName Context:(NSString *)text
    {
        UIImage *sourceImage = [UIImage imageNamed:imageName];
        CGSize imageSize; //画的背景 大小
        imageSize = [sourceImage size];
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
        [sourceImage drawAtPoint:CGPointMake(0, 0)];
        //获得 图形上下文
        CGContextRef context=UIGraphicsGetCurrentContext();
        CGContextDrawPath(context, kCGPathStroke);
        CGFloat nameFont = 20.f;
        //画 自己想要画的内容
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:nameFont]};
        CGRect sizeToFit = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, nameFont) options:NSStringDrawingUsesDeviceMetrics attributes:attributes context:nil];
        NSLog(@"图片: %f %f",imageSize.width,imageSize.height);
        NSLog(@"sizeToFit: %f %f",sizeToFit.size.width,sizeToFit.size.height);
        CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
        [text drawAtPoint:CGPointMake((imageSize.width-sizeToFit.size.width)/2,0) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:nameFont]}];
        //返回绘制的新图形
        
        UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        return newImage;
    }
    挥毫泼墨,书写人生篇章
  • 相关阅读:
    JSTL标签详解
    jQuery核心基础
    JavaWeb文件上传与下载
    AOP编程模式
    2022.3.1
    2022.2.7
    Postman安装完之后打开空白
    vue项目中vueparticles的使用
    字符串中出现次数最多的字符及其出现的次数
    elementui select选择器滑动加载下一页
  • 原文地址:https://www.cnblogs.com/Jusive/p/6030694.html
Copyright © 2020-2023  润新知