2010-12-14 14 views
6
CGContextRef context = ??; // get from UIImage *oldImage 

    CGContextSaveGState(context); 
    CGRect drawRect = CGRectMake(0, 0, 320, 480); 
    CGContextConcatCTM(context, transform); 
    UIImage *newImage = [[UIImage alloc] init]; 
    CGContextDrawImage(context, drawRect, newImage.CGImage); 
    [newImage drawInRect:CGRectMake(0, 0, 320, 480)]; 

    CGContextRestoreGState(context);

要するに、私がしたいのは[UIImage - >いくつかの変換 - >変換されたUIImage]です。UIImageからどのようにCGContextRefを取得できますか?

アイデア?本当にありがとう!!私は何が必要だと思う

答えて

8

はこれです:

UIGraphicsBeginImageContextWithOptions(newImageSize, YES, 0); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
// drawing commands go here 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIGraphicsGetImageFromCurrentImageContext()は自動解放UIImageのインスタンスを返すこと。

+0

ありがとうございますが、私は何もしなかったのに逆さまなイメージを得ましたか? –

+0

Core Graphicsを描画に使用する場合(CGContextDrawImage()など)は、反転した座標系を使用していることに注意してください。 UIImageの描画方法では、座標系をプリフリップする必要はありません。 – Costique

+0

Noob質問:これはひどく無駄なようです...私はちょうど私のイメージの上に少しのデータを追加したいと思います。私はこれのために全体を再描画することは嫌いです。 – Ralphleon

関連する問題