How to change the skin color of face from the source image in ios?

后端 未结 6 409
失恋的感觉
失恋的感觉 2021-01-31 21:45

MY code: How to manage RGB value for differet shades of face,and how to apply? this code will change the color of face along with hair,but i want 1.only face to be colored excl

6条回答
  •  温柔的废话
    2021-01-31 21:56

    Try Masking the image ... it will help to change the specific range of colors defined in mask

    Code:

    - (UIImage *)doctorTheImage:(UIImage *)originalImage
    {
    
       const float brownsMask[6] = {85, 255, 85, 255, 85, 255};
    
    
        UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];
    
        UIGraphicsBeginImageContext(originalImage.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        CGContextSetRGBFillColor (context, 1.0,1.0, 1.0, 1);
    
    
        CGContextFillRect(context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height));
    
        CGImageRef brownRef = CGImageCreateWithMaskingColors(imageView.image.CGImage, brownsMask);
    
        CGRect imageRect = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
    
        CGContextTranslateCTM(context, 0, imageView.image.size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
        //CGImageRef whiteRef = CGImageCreateWithMaskingColors(brownRef, whiteMask);
        CGContextDrawImage (context, imageRect, brownRef);
    
        //[originalImage drawInRect:CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height)];
    
        CGImageRelease(brownRef);
       // CGImageRelease(whiteRef);
    
        UIImage *doctoredImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return doctoredImage;
    }
    

提交回复
热议问题