iOS-仅在非透明区域使用颜色覆盖UIImage? 我有一个白色的图像,中间有一个透明区域:
我想用颜色(仅非透明区域)覆盖它,使其看起来像这样: 我该怎么做iOS-仅在非透明区域使用颜色覆盖UIImage? 我有一个白色的图像,中间有一个透明区域:,ios,objective-c,uiimage,Ios,Objective C,Uiimage,我想用颜色(仅非透明区域)覆盖它,使其看起来像这样: 我该怎么做 我已经研究过了,但它覆盖了整个图像,包括不透明区域。因此,您的图像实际上是一个“遮罩”。使用“CGContextClipToMask”调用和您引用的上述代码进行操作。尝试以下代码,它会给出您想要的确切信息 UIGraphicsBeginImageContextWithOptions(imgView.image.size, YES, 0); CGContextRef context = UIGraphicsGetC
我已经研究过了,但它覆盖了整个图像,包括不透明区域。因此,您的图像实际上是一个“遮罩”。使用“CGContextClipToMask”调用和您引用的上述代码进行操作。尝试以下代码,它会给出您想要的确切信息
UIGraphicsBeginImageContextWithOptions(imgView.image.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, (CGRect){ {0,0}, imgView.image.size} );
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, imgView.image.size.height);
CGContextConcatCTM(context, flipVertical);
CGContextDrawImage(context, (CGRect){ {0,0}, imgView.image.size }, [imgView.image CGImage]);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imgView setImage:image];