从iOS中的UIIMAGE中删除掩码



我在iOS中掩盖了一个uiimage。我现在要删除那个面具。我将如何实现它。这是我掩盖图像的代码:

UIColor *header1Color = [UIColor colorWithRed:0.286 green:0.286 blue:0.286 alpha:0.1];
        UIImage *img = self.calorie_image.image;
//        int width = img.size.width;  //308
//        int height = img.size.height; //67
        UIGraphicsBeginImageContext(img.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [header1Color setFill];
        // translate/flip the graphics context (for transforming from CG* coords to UI* coords
        CGContextTranslateCTM(context, 0, img.size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
        // set the blend mode to color burn, and the original image
        CGContextSetBlendMode(context, kCGBlendModeColorBurn);
        CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
        CGContextDrawImage(context, rect, img.CGImage);
        //calorie_value = 230;
        int x = 200;
        int y = 0;
        int mwidth = 120;
        int mheight = 67;
        NSString *zone = @"";
        NSArray *min = [[NSArray alloc] initWithObjects:@"0", @"1200", @"1800", @"2200", nil];
        NSArray *max = [[NSArray alloc] initWithObjects:@"1200", @"1800", @"2200", @"3500", nil];
        NSArray *x_values = [[NSArray alloc] initWithObjects:@"42", @"137", @"200", @"320", nil];
        NSArray *mwidth_values = [[NSArray alloc] initWithObjects:@"278", @"183", @"120", @"0", nil];
        NSArray *zones = [[NSArray alloc] initWithObjects:@"red", @"green", @"orange", @"red", nil];
        for (int i=0; i < 4; i++) {
            if(calorie_value >= [min[i] integerValue] && calorie_value <= [max[i] integerValue]) {
                zone = zones[i];
                x = [x_values[i] integerValue];
                mwidth = [mwidth_values[i] integerValue];
                break;
            }
        }
        if([[DiabetaDbTransaction getToadyCalories] integerValue] > 0) {
            CGContextClearRect(context, CGRectMake(x,y,mwidth,mheight));
        }
        // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
        CGContextClipToMask(context, rect, img.CGImage);
        CGContextAddRect(context, rect);
        CGContextDrawPath(context,kCGPathFill);
        // generate a new UIImage from the graphics context we drew onto
        UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        self.calorie_image.image = coloredImg;

如何将原始图像存储为ivar当您只想删除面膜时:

@implementation viewController { uiimage *coloredimg_orginal;}

在将蒙版添加到图像设置coloredimg_orginal之前。

coloredimg_orginal = self.calorie_image.image;

和在删除蒙版的功能中,只是设置有孔图像而不是掩码图像

self.calorie_image.image = coloredimg_orginal;

(对不起,我的英语不好)

相关内容

  • 没有找到相关文章

最新更新