In the cocos2d I can not use some method like UIGraphicsGetCurrentContext
so i do it like that way following this:
memset(textData, 0, sW*sH*4);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(textData, sW, sH, 8, sW*4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease( colorSpace );
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextTranslateCTM(context, 0.0f, sH);
CGContextScaleCTM(context, 1.0f, -1.0f);
UIGraphicsPushContext(context);
NSString* sstr = [NSString stringWithCString:(const char*)str encoding:NSUnicodeStringEncoding];//its right
UIFont* font = [UIFont fontWithName:@"arial" size:12];
[sstr drawInRect:CGRectMake(x, sH-y,100,100) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
UIGraphicsPopContext();
CGContextRelease(context);
When I debug and breakpoint at UIGraphicsPopContext
, the content of textData
is always zero in the memory view, somebody help me. context
and textData
is not nil.