Dmitry Nelepov
Dmitry Nelepov

Reputation: 7306

How to add path to UIImage which will remove pixels?

I have UIImage with some image.

And i have UIBezierPath (user signature).

How to make what path erase pixels in UIImage for alpha.

Simply like scratch some uiimage?

i try

UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);
    [[UIColor clearColor] setStroke];

    [self.blurImageView.image drawAtPoint:CGPointZero];
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
    [self.path stroke];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    self.blurImageView.image = img;

But it just draw black line.

Upvotes: 0

Views: 235

Answers (1)

Hamish
Hamish

Reputation: 80951

You're passing YES into the opaque parameter of UIGraphicsBeginImageContextWithOptions. Therefore instead of creating transparency, kCGBlendModeClear will fill with black (as there's no alpha channel to clear).

The fix is to use a non-opaque context.

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

Upvotes: 3

Related Questions