2009-02-06 50 views
1

我有一個320x480的PNG,我想在iPhone上進行貼圖/操作,但這些尺寸顯然不是2的冪。我已經在512x512 PNG上測試了我的紋理貼圖操作算法一個320x480的黑色背景疊加在其上,以原點(左下角(0,0))爲中心,320x480的區域在iPhone屏幕上正確定向/居中/縮放。將PNG複製到更大的空白/代碼生成紋理中的最佳方法? (OpenGL ES 1.1/iPhone)

我現在想要做的是進展到可以採用320x480源圖像並將其應用於代碼中生成的空白/黑色背景512x512紋理的位置,以便兩者合併爲一個紋理,以便我可以應用我在512x512測試中使用的頂點和紋理座標。這將最終用於相機拍攝和相機卷源圖像等。

任何想法? (必須爲OpenGL ES 1.1而不使用GL工具包等)。

謝謝, 阿里

回答

0

一種方法我發現工作是簡單地兩個圖像繪製到當前上下文中,然後提取所得到的組合圖像。有沒有更適合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,但這確實有效。