project_files/HedgewarsMobile/Classes/UIImageExtra.m
changeset 3903 db01c37494af
parent 3829 81db3c85784b
child 3910 dd47efbdec46
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Sat Sep 25 03:04:22 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Sat Sep 25 18:38:05 2010 +0200
@@ -207,4 +207,17 @@
     return newImage;
 }
 
+// by http://www.sixtemia.com/journal/2010/06/23/uiimage-negative-color-effect/
+-(UIImage *)convertToNegative {
+    UIGraphicsBeginImageContext(self.size);
+    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
+    [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
+    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
+    CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
+    CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.size.width, self.size.height));
+    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
+    UIGraphicsEndImageContext();
+    return result;
+}
+
 @end