LoginSignup
3
3

More than 5 years have passed since last update.

alpha値のみで指定色にimage

Posted at

imageWithRenderingMode :UIImageRenderingModeAlwaysTemplateのような処理。
アルファ値のみを対象に指定した色で出力

mimage
@interface UIImage (mimage)
-(UIImage*)templated:(UIColor*)color
@end

@implementation UIImage (mimage)
-(UIImage*)templated:(UIColor*)color
{
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
    [color set];
    CGRect rc = {CGPointZero, self.size};
    UIRectFill(rc);
    [self drawInRect:rc blendMode:kCGBlendModeDestinationIn alpha:1.0];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
@end

最初に指定色をベタ塗りして自前画像のalpha成分で抜き

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3