zoukankan      html  css  js  c++  java
  • 给图片画文字

    - (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;
    }
    挥毫泼墨,书写人生篇章
  • 相关阅读:
    飞入飞出效果
    【JSOI 2008】星球大战 Starwar
    POJ 1094 Sorting It All Out
    POJ 2728 Desert King
    【ZJOI 2008】树的统计 Count
    【SCOI 2009】生日快乐
    POJ 3580 SuperMemo
    POJ 1639 Picnic Planning
    POJ 2976 Dropping Tests
    SPOJ QTREE
  • 原文地址:https://www.cnblogs.com/Jusive/p/6030694.html
Copyright © 2011-2022 走看看