2011-05-18 82 views
1

在cocos2d中,可以選擇「更改」精靈的顏色。例如:我有一個白色圖像,然後執行代碼,圖像變成我指定的任何顏色。如何在不使用cocos2d庫的情況下做同樣的事情?Iphone SDK:更改圖像顏色

我知道這是可能的,我在5個月前自己做了這樣的事情,但在典型的情況下,我以某種方式失去了代碼。

+0

創建CGContext,將圖像繪製到上下文中,獲取像素數據,迭代,修改和保存。 – TheBlack 2011-05-19 02:49:05

+0

它也許對你有用。 https://github.com/mattgemmell/MGImageUtilities – sathiamoorthy 2011-11-21 13:53:58

回答

0

試試這個

UIImage *newImage = [_imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
UIGraphicsBeginImageContextWithOptions(image.size, NO, newImage.scale); 
[yourTintColor set]; 
[newImage drawInRect:CGRectMake(0, 0, image.size.width, newImage.size.height)]; 
newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

_imgView.image = newImage; 
0

第一套的UIImageView圖像然後在下面的代碼片段使用。

imgView.image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
[imgView setTintColor:[UIColor redColor]];