2011-05-29 21 views

回答

5

我相信你想用CGContextRef在所需的地方畫出所有的圖像,然後得到最終的圖像。代碼看起來像這樣:

CGContextRef context = CGBitmapContextCreate(nil, desired_width, desired_height, bitsPerComponent, bytesPerRow, CGColorSpaceCreateDeviceRGB(), CGImageGetBitmapInfo(image)); 
//This code is to ilustrate what you have to do: 
for(image in your Images) { 

    CGContextDrawImage(context, CGRectMake(currentImage.frame.origin.x, currentImage.frame.origin.y, CGImageGetWidth(currentImage), CGImageGetHeight(currentImage), currentImage); 
} 

CGImageRef mergeResult = CGBitmapContextCreateImage(context); 

mergedImage = [[UIImage alloc] initWithCGImage:mergeResult]; 
CGContextRelease(context); 
CGImageRelease(mergeResult); 
+1

太棒了!我會嘗試!非常感謝=) – 2011-05-29 20:54:11

4

CGContextRefs可以隨時創建,這可以讓你做所有類型的圖像操作。

使用CGBitmapContextCreate創建上下文和CGBitmapContextCreateImage以獲得最終結果。

相關問題