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