0
回答
iphone 中字符串生成纹理图片
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

- (void) getBitmapfromText:(NSString *)text iSize:(CGSize)imageSize 
{
// Create a bitmap graphics context of the given size
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height,8, imageSize.width, colorSpace, kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);

if (context== NULL) {
fprintf (stdout, "Context not created!");
}

// Custom CGContext coordinate system is flipped with respect to UIView, so transform, then push
CGContextTranslateCTM(context, 0, imageSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
UIGraphicsPushContext(context);
// Inset the text rect then draw the text
CGRect textRect = CGRectMake(1, 1, imageSize.width - 2, imageSize.height - 2);
UIFont *font = [UIFont boldSystemFontOfSize:12];
[[UIColor blackColor] set];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

// Create and return the UIImage object
CGImageRef imageRef = CGBitmapContextCreateImage(context);  // 方法2 用到了这个
uiimg = [[UIImage alloc] initWithCGImage:imageRef];  //  这里uiimg是个全局变量
UIGraphicsPopContext();

CGContextRelease(context);
CGImageRelease(imageRef);
}

 

熟悉windows下GDI编程的同志一看就知道, 方法有点类似。


原文链接:http://blog.csdn.net/favormm/article/details/5327715
<无标签>
举报
长平狐
发帖于5年前 0回/192阅
顶部