2012-03-30 48 views

回答

6

它是如此簡單,你必須選擇圖像,並在下面的代碼

UIGraphicsBeginImageContext(renderImage.size); 
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); 
[renderImage drawInRect:CGRectMake(0, 0, renderImage.size.width, renderImage.size.height)]; 
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference); 
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor); 
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, renderImage.size.width, renderImage.size.height)); 
renderImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
4

製作的方法設置圖像:

- (UIImage *)makeImageNegative:(UIImage *)image{ 
UIGraphicsBeginImageContext(image.size); 
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); 
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference); 
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor  whiteColor].CGColor); 
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height)); 
UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();  
return returnImage; 
} 
+0

@CocoaMatters可能是他寫的同時你發佈了! – 2012-03-30 10:09:21

+0

@Jennis同意你的評論 – Hiren 2012-03-30 10:15:40

+0

是啊對不起,我寫了它,而你正在寫它 – MCKapur 2012-03-30 10:16:20