0

我希望UIimageUIColor. 请参阅下面的代码。它不适合我。我正在尝试将图像中的浅色遮盖为中等棕色。

ivMasking1是源Imageview

代码:

    UIGraphicsBeginImageContext(ivMasking1.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    const CGFloat myMaskingColors[6] = {124, 255,  68, 222, 0, 165};
    CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors (ivMasking1.image.CGImage,
                                                         myMaskingColors);
    CGRect myContextRect = CGRectMake(0,0,50,50);

    CGContextDrawImage (context, myContextRect, myColorMaskedImage);

    ivMasking2 = [[UIImageView alloc] initWithImage:UIGraphicsGetImageFromCurrentImageContext()];
    ivMasking2.frame = CGRectMake(0 ,125, 300,200);
    ivMasking2.contentMode = UIViewContentModeScaleAspectFit;
    ivMasking2.backgroundColor = [UIColor redColor];
    [self.view addSubview:ivMasking2];

谢谢!PS:您可以参考主题:Masking an Image with Color from Quartz Programming Guide

4

0 回答 0