Skip to content

Commit

Permalink
Added a mask to the image category
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Imdieke committed Sep 14, 2012
1 parent 0fa4f9b commit 38519cf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Example/UIImage+KGNoise.m
Expand Up @@ -27,6 +27,8 @@ - (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)bl
kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);

CGContextSaveGState(context);

// Flip context
CGContextTranslateCTM(context, 0, self.size.height * self.scale);
CGContextScaleCTM(context, self.scale, -self.scale);
Expand All @@ -36,6 +38,10 @@ - (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)bl
// Draw the image
[self drawAtPoint:CGPointMake(0.0, 0.0)];

CGContextRestoreGState(context);

CGContextClipToMask(context, CGRectMake(0.0, 0.0, self.size.width * self.scale, self.size.height * self.scale), [self CGImage]);

// Noise on top
[KGNoise drawNoiseWithOpacity:opacity andBlendMode:blendMode];

Expand Down

0 comments on commit 38519cf

Please sign in to comment.