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。