2012-02-06 8 views
3

私は文字列変数から画像を作成しています。以下は、画像を作成するためのコードスニペットです。NSStringから画像を正しく作成する

-(UIImage *)imageFromText:(NSString *)text FontName:(UIFont *)font 
{ 
    // set the font type and size 
    //UIFont *font = [UIFont systemFontOfSize:20.0]; 
    CGSize size = [text sizeWithFont:font]; 

    UIGraphicsBeginImageContext(size); 

    [text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font]; 

    // transfer image 
    CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES); 
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); 

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext();  

    return image; 
} 

上記のコードはうまくいきますが、最終的な画像がぼやけるという問題があります。 上記のコードに問題がある場合は、アドバイスをお願いします。代わりUIGraphicsBeginImageContext(size

+0

注:上記のコードはiOS 7以降廃止予定です – Raptor

答えて

1

使用UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)

セットスケール画面サイズに応じ。これはあなたを助け、ぼやけた画像を得ることはありません。

関連する問題