2011-07-14 11 views
0

CGContextSelectFontを使用してビットマップに描画しますが、特定のエンコーディングを使用します。別の言語を使用する場合、これは機能しません。現在の言語に基づいてエンコーディングを選択する推奨方法は何ですか?ローカリゼーションは正常に動作しています。CGContextSelectFontを使用して現在の言語に基づいてエンコーディングを選択する方法は?

CGContextDrawImage(context, rect, image.CGImage); 

NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"WaitingForDownloadFor"],title]; 
const char *text = [temp UTF8String]; 
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman); //*** line in question 
CGContextSetTextDrawingMode(context, kCGTextFill); 
CGContextSetRGBFillColor(context, 1, 1, 1, 1); 
CGContextShowTextAtPoint(context, 10, h/2, text, strlen(text)); 
+0

通常、Mac OS XおよびiOSのすべての文字列はUTF-8です。 [この質問](http://stackoverflow.com/questions/275437/unicode-character-not-showing)を参照してください。 –

+0

これは本当に上記の答えです.... – ort11

答えて

0

ここでは、質問に答えてくれるコードがあります。ポインタのおかげ...ローカリゼーションクラスはカスタムクラスです。

NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"Downloading"],title]; 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); 
CGContextDrawImage(context, rect, image.CGImage);  
UIGraphicsPushContext(context); 
CGContextSetRGBFillColor(context, 1, 1, 1, 1); 
UIFont* font = [UIFont fontWithName:@"Arial" size:18.0]; 
// need to do this or Mirrored Backwards 
CGContextTranslateCTM(context, 0, h); 
CGContextScaleCTM(context, 1.0, -1.0); 
[temp drawAtPoint:CGPointMake(10.0,h/2) withFont:font]; 
CGImageRef imageRef = CGBitmapContextCreateImage(context); 
UIImage *image2 = [[UIImage imageWithCGImage:imageRef] retain]; 
CGContextRelease(context); 
CGColorSpaceRelease(colorSpace);  
UIGraphicsPopContext(); 
関連する問題