Fork me on GitHub

CGBitmapContextCreate创建的CGContextRef画文字

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, 
  pageSize.width,        /* size_t width */
  pageSize.height,       /* size_t height */
  8,      /* bits per component 32/4 */
  pageSize.width * 4,  /* bytes per row 每行字节数,每一个位图像素的代表是4个字节 */
  colorSpace,            /* CGColorSpaceRef */
  kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);


UIGraphicsPushContext(ctx);

CGContextTranslateCTM(ctx, 0, 480);
CGContextScaleCTM(ctx, 1.0, -1.0);

// 文字内容
[@"中文中文中文" drawInRect:CGRectMake(10, 25, MAX_WIDTH, MAX_HEIGHT) withFont:font];
UIGraphicsPopContext();

posted on 2012-03-25 09:20  pengyingh  阅读(358)  评论(0)    收藏  举报

导航