您的位置:首页 > 产品设计 > UI/UE

[iOS代码] 根据文字生成图片UIImage

2013-05-09 19:57 351 查看
    CGColorSpaceRef colorSpace =
CGColorSpaceCreateDeviceRGB();
   
CGContextRef context =
CGBitmapContextCreate(NULL, dsize.width, dsize.height,
8,
4*dsize.width, colorSpace,
kCGImageAlphaPremultipliedFirst);
   
CGRect imageRect =
CGRectMake(0,
0, dsize.width, dsize.height);
   
UIColor* tColor = [[DisplayText
sharedInstance] textColor];
   
float tred =
0;
   
float tgreen =
0;
   
float tblue =
0;
   
float tAlpha =
0;
    [tColor
getRed:&tred green:&tgreen
blue:&tblue alpha:&tAlpha];
   
CGContextSetRGBFillColor(context, tred, tgreen, tblue, tAlpha);
   
CGContextTranslateCTM(context,
0, imageRect.size.height);
   
CGContextScaleCTM(context,
1, -1);

    UIGraphicsPushContext(context);
   
UIFont* sFont = [UIFont
boldSystemFontOfSize:fontSize];

    [[[DisplayText
sharedInstance] displayText]
drawAtPoint:CGPointMake(0,
0)
                                                  
withFont:sFont];

    UIGraphicsPopContext();

    

    CGImageRef  bgRef =
CGBitmapContextCreateImage(context);

CGContextRelease(context);

CGColorSpaceRelease(colorSpace);
UIImage
* newBg = [UIImage
imageWithCGImage:bgRef];

CGImageRelease(bgRef);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: