• ios --图片文字组合头像那点事


    /**
     图片文字组合头像那点事
    
     @param string 昵称
     @param imageSize 图片尺寸
     @param imageColor 图片颜色
     @return 返回的 图片
     */
    + (UIImage *)gl_creatImageWithString:(NSAttributedString *)string
                               imageSize:(CGSize)imageSize
                              imageColor:(UIColor *)imageColor
    {
        //通过自己创建一个context来绘制,通常用于对图片的处理
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);
        //获取上下文
        CGContextRef context = UIGraphicsGetCurrentContext();
        //设置填充颜色
        CGContextSetFillColorWithColor(context, imageColor.CGColor);
        //直接按rect的范围覆盖
        CGContextAddEllipseInRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height));
        CGContextFillPath(context);
        
        CGSize stringSize = [string size];
        CGFloat x = (imageSize.width - stringSize.width)/2.0;
        CGFloat y = (imageSize.height - stringSize.height)/2.0;
        
        [string drawInRect:CGRectMake(x, y, stringSize.width, stringSize.height)];
        
        UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newimg;
    }
  • 相关阅读:
    hdu 1045 Fire Net
    hdu 1044 Collect More Jewels
    hdu 1043 Eight
    hdu 1042 N!
    hdu 1041 Computer Transformation
    hdu 1040 As Easy As A+B
    CI在ngnix的配置
    angularjs表单验证checkbox
    chrome浏览器跨域设置
    angularjs向后台传参,后台收不到数据
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/9565364.html
Copyright © 2020-2023  润新知