Iphone 如何从UIImage获取CGContextRef?

Iphone 如何从UIImage获取CGContextRef?,iphone,uiimage,cgcontext,Iphone,Uiimage,Cgcontext,简而言之,我想做的是[UIImage->进行一些变换->变换UIImage] 有什么想法吗?非常感谢 我想你需要的是: CGContextRef context = ??; // get from UIImage *oldImage CGContextSaveGState(context); CGRect drawRect = CGRectMake(0, 0, 320, 480); CGContextConcatCTM(context, transform

简而言之,我想做的是[UIImage->进行一些变换->变换UIImage]


有什么想法吗?非常感谢

我想你需要的是:

    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);

请注意,
UIGraphicsGetImageFromCurrentImageContext()
返回一个自动删除的UIImage实例。

谢谢,但我什么也没做,却得到了一个颠倒的图像?如果使用核心图形进行绘图(例如
CGContextDrawImage()
),请记住它使用的是翻转坐标系。UIImage绘图方法不需要预先翻转坐标系。。。我只想在我的图像上添加一点数据。我不喜欢为此重画整件事。@Ralveron“在顶部添加图形”相当于绘图和混合,这需要图形引擎的全部功能。@Costique我想这是我应该考虑的方式。这是混合真的。。。我总是喜欢想“点点滴滴”:)谢谢你让我的想法正确!
UIGraphicsBeginImageContextWithOptions(newImageSize, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing commands go here
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();