3

いくつかの透明なピクセルを含む画像がある場合、透明なピクセルを白で色付けし、目的の c で残りの画像を透明にする可能性はありますか?

ありがとう!

4

2 に答える 2

0

これが私が使用しているものです:

- (UIImage *)imageWithTintedColor:(UIImage *)image withTint:(UIColor *)color withIntensity:(float)alpha
{
    CGSize size = image.size;

    UIGraphicsBeginImageContextWithOptions(size, FALSE, [[UIScreen mainScreen] scale]);
    CGContextRef context = UIGraphicsGetCurrentContext();

    [image drawAtPoint:CGPointZero blendMode:kCGBlendModeNormal alpha:1.0];

    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextSetBlendMode(context, kCGBlendModeSourceAtop);
    CGContextSetAlpha(context, alpha);

    CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(CGPointZero.x, CGPointZero.y, image.size.width, image.size.height));

    UIImage * tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return tintedImage;
}
于 2013-10-02T14:58:39.200 に答える