Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a mask to the image category

  • Loading branch information...
commit 38519cf49f097d7d9ed210c3bc6b1ab1cd31b1aa 1 parent 0fa4f9b
Cory Imdieke authored
Showing with 6 additions and 0 deletions.
  1. +6 −0 Example/UIImage+KGNoise.m
6 Example/UIImage+KGNoise.m
View
@@ -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);
@@ -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];
Please sign in to comment.
Something went wrong with that request. Please try again.