UIImage *myImage = …;
CGLayerRef layer = CGLayerCreateWithContext(destinationContext, myImage.size, /*auxiliaryInfo*/ NULL);
if (layer) {
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextDrawImage(layerContext, (CGRect){ CGPointZero, myImage.size }, myImage.CGImage);
//Use CGContextDrawLayerAtPoint or CGContextDrawLayerInRect as many times as necessary. Whichever function you choose, be sure to pass destinationContext to it—you can't draw the layer into itself!
CFRelease(layer);
}
这在技术上是我的第一个iPhone代码(我只在Mac上编程),所以要小心。尽管如此,我曾经使用过CGLayer,并且据我所知,Quartz在iPhone上并没有什么不同。
...并作为UIImage返回。
我不知道如何做到这一点,从未与UIKit合作过。
@Joe - 如果您有要回答的问题,请做。这个网站的重点不是为了获得任意点,而是为了帮助他人。这个分数仅仅是积极行为的强化。仅仅因为有人没有对你的答案进行投票并不意味着你浪费了时间来编写答案。至少,你可能在回答问题的过程中学到了一些东西。 – 2011-01-05 15:45:06
@Joe如果你想帮忙,请帮忙。 – willc2 2011-01-08 19:27:31