我已使用效果良好的蒙版图像在图像上应用了填充色。但是我无法在蒙版图像上应用笔触颜色(即边框)。它是在rect中绘制笔触,而不是在蒙版图像的边框中绘制。这是下面的代码:-
- (UIImage *)imageMaskedWithColor:(UIColor *)maskColor
{
NSParameterAssert(maskColor != nil);
CGRect imageRect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
UIImage *newImage = nil;
UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, self.scale);
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, 1.0f, -1.0f);
CGContextTranslateCTM(context, 0.0f, -(imageRect.size.height));
CGContextClipToMask(context, imageRect, self.CGImage);
CGContextSetFillColorWithColor(context, maskColor.CGColor);
CGContextFillRect(context, imageRect);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.3);
CGContextStrokeRectWithWidth(context, imageRect, 2.0);
newImage = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return newImage;
}
我在做什么错了?