Skip to content

Instantly share code, notes, and snippets.

@puelocesar
Created September 19, 2017 23:20
Show Gist options
  • Save puelocesar/d3f0bbed74d97ec94de212e17e7adba1 to your computer and use it in GitHub Desktop.
Save puelocesar/d3f0bbed74d97ec94de212e17e7adba1 to your computer and use it in GitHub Desktop.
UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef outputContext = UIGraphicsGetCurrentContext();
CGContextScaleCTM(outputContext, 1.0, -1.0);
CGContextTranslateCTM(outputContext, 0, -self.size.height);
// draw base image
CGContextDrawImage(outputContext, imageRect, self.CGImage);
// draw effect image
if (hasBlur) {
CGContextSaveGState(outputContext);
if (maskImage) {
CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
}
CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
CGContextRestoreGState(outputContext);
}
// output image is ready
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment