一種方法我發現工作是簡單地兩個圖像繪製到當前上下文中,然後提取所得到的組合圖像。有沒有更適合OpenGL的方法可能更有效?
// CGImageRef for background image
// CGImageRef for foreground image
// CGSize for current context
// Define CGContextRef for current context
// UIGraphicsBeginImageContext using CGSize
// Get value for current context with UIGraphicsGetCurrentContext()
// Define 2 rectangles, one for the background and one for the foreground images
// CGContextDrawImage(currentContext, backgroundRect, backgroundImage);
// CGContextDrawImage(currentContext, foregroundRect, foregroundImage);
// UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
// spriteImage = finalImage.CGImage();
// UIGraphicsEndImageContext();
此時,您可以繼續使用spriteImage作爲紋理圖像源,這將是一個空白的512×512的PNG與PNG小320x480例如組合。
我將用代碼生成的圖像替換512x512空白PNG,但這確實有效。