use*_*169 4 iphone core-graphics colors iphone-sdk-3.1
我有一个iPhone应用程序,允许一个人用手指在屏幕上绘制一些东西.他们在黑色背景上画一条白线.但是,当我将此图像上传到Web服务器时,该行本身是白色的.我一直试图通过核心图形库来寻找一种方法来反转绘制图像的颜色.没有背景设置,所以它应该是透明的.执行图像反转应将白色交换为黑色.
有谁知道这是否可以通过核心图形库?
干杯
use*_*169 14
我最终找到了一个很好的方法.我没有简单地将原始图像的背景透明化,而是将其设为黑色.现在黑色背景上有白线.然后,这只是一个问题:
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();
变量"图像"是黑色背景上带有白线的原始图像.感谢David Sowsy的帮助