图像上的IOS行-是否可以反转颜色?
我在我的应用程序中的UIImage上面画了一条线。我希望这条线是一个“独特的”颜色从背景画。如果图像中有白色区域,如果在其顶部绘制线条,则不应为白色。这容易实现吗 现在我使用白色作为线条。代码如下:图像上的IOS行-是否可以反转颜色?,ios,uiimage,Ios,Uiimage,我在我的应用程序中的UIImage上面画了一条线。我希望这条线是一个“独特的”颜色从背景画。如果图像中有白色区域,如果在其顶部绘制线条,则不应为白色。这容易实现吗 现在我使用白色作为线条。代码如下: [myImage drawInRect:CGRectMake(0,0,200,200)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGet
[myImage drawInRect:CGRectMake(0,0,200,200)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1,1,1, 1.0);//RGB all 1)
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pt1.x, pt1.y); // pt1 -start point
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pt2.x, pt2.y); // pt2 - end point
正如你们所看到的,我用了1,1,1来获得从点pt1到pt2的图像顶部的白线。当在“myImage”的白色区域上绘制时,该线将不可见。我想让它在白色的上面也可见。我怎样才能做到这一点
不确定这个论坛上是否已经有了答案。但是找不到像这样的东西
提前谢谢你的帮助
编辑
@罗布·马约夫的回答非常适合我。以下是我的最终代码,以方便查看:
[myImage drawInRect:CGRectMake(0,0,200,200)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1,1,1, 1.0);//RGB all 1)
CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), CGSizeMake(2.0f, 2.0f), 1.0f,
[[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:.6] CGColor]);
//CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeExclusion);
//CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeDifference);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pt1.x, pt1.y); // pt1 -start point
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pt2.x, pt2.y); // pt2 - end point
以下是两项建议:
CGContextSaveGState
和CGContextRestoreGState
kCGBlendModeDifference
或KCGBlendModeExclution
。看比你好多了。它工作得很好。所有三个(setshadow、BlendModeDifference和BlendModeExclusion)都工作正常。我选择了setShadow,因为它更适合我的页面。我已将最终代码作为编辑添加到我的问题中。再次感谢你的帮助