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);
这篇博客介绍了如何在iOS中将文字转换为UIImage。通过创建颜色空间和位图上下文,设置文字颜色,利用UIFont和UIGraphicsContext绘制文字,最后生成并释放CGImage及颜色空间,得到UIImage对象。
3267

被折叠的 条评论
为什么被折叠?



