2011-07-27 5 views
0
- (void)drawRect:(CGRect)rect { 
    // Drawing code. 
    stickerImage = [UIImage imageNamed:@"betaImage.png"]; 
    CGSize size = stickerImage.size; 
    UIGraphicsBeginImageContext(size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(context, 0.5f * size.width, 0.5f * size.height); 
    CGContextRotateCTM (context, 90 * M_PI/180); 
    [stickerImage drawInRect:(CGRect){ { -size.width * 0.5f, -size.height * 0.5f }, size }]; 

    UIGraphicsEndImageContext(); 
} 

を示していない、それは何もCGContextRotateCTMをいただきました私のコードで間違って私は見つけることができないもの

答えて

0

ええ、結果イメージを取得する前にコンテキストを終了しないでください。コード例では、結果イメージを取得する必要があります。

UIImage* yourImage = UIGraphicsGetImageFromCurrentImageContext(); 

または他の親メソッドに終了コンテキストを渡すだけです。

Morgan Harris氏によると、すべての画像操作はUIGraphicsBeginImageContext()とUIGraphicsEndImageContext()の間で行う必要があります。

1

を示していないと、画像のコンテキストを開始し、終了しないでください - それはUIImageに描画するためです。現在のコンテキストは、drawRectのビューのコンテキストにすでに設定されています。 - UIGraphicsGetCurrentContext()は、正しいコンテキストをボックス外に提供します。

つまり、UIGraphicsBeginImageContext()およびUIGraphicsEndImageContext()を削除します。

関連する問題