我一直想寫使用Quartz一個層上的形象,但我看到的是完全空的圖片...這是代碼誤差UIGraphicsGetCurrentContext
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect backRect = CGRectMake (0, 0, image.size.width, image.size.height);
CGLayerRef backLayer = CGLayerCreateWithContext (context, image.size, NULL);
CGContextRef backContext = CGLayerGetContext (backLayer);
CGContextDrawImage(backContext, backRect, image.CGImage);
你們可以告訴我什麼是錯的用這個代碼?
圖像是用相機拍攝的UIImage。
是的,圖像在那裏。如果我用
替換上述代碼UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
我看到圖像。但是我必須把它放在一個層面上,因爲它是一個精靈。
行CGContextDrawImage(backContext,backRect,image.CGImage);?它不是在上下文上繪製圖層嗎? – SpaceDog 2009-09-07 21:00:55
不,您在創建的新圖層上繪製圖像,但圖層本身應添加到當前上下文中。 – 2009-09-07 21:03:01
啊,好的。我已經添加了行\t CGContextDrawLayerAtPoint(context,CGPointMake(0,0),backLayer);在代碼的最後,我仍然得到空的圖像......我的頭髮在絕望中變得灰暗...... – SpaceDog 2009-09-07 21:10:08