Skip to content

Instantly share code, notes, and snippets.

@skwashua
skwashua / blurImage
Created December 10, 2013 08:06
CoreImage GaussianBlur
+(UIImage *)blurImage:(UIImage *)image withStrength:(float)strength
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [[CIImage alloc] initWithCGImage:image.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:@"inputImage"];
[filter setValue:[NSNumber numberWithFloat:strength] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
float scale = [[UIScreen mainScreen] scale];
@skwashua
skwashua / iosScreenshot
Created December 10, 2013 08:08
Screenshot from iOS
+(UIImage *) screenshot
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
else
UIGraphicsBeginImageContext(imageSize);
@skwashua
skwashua / ios7Screenshot
Created December 10, 2013 16:38
iOS 7 Screenshot
CGSize imageSize = [[UIApplication sharedApplication] keyWindow].bounds.size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, [[UIScreen mainScreen] scale]);
[[[UIApplication sharedApplication] keyWindow] drawViewHierarchyInRect:[[UIApplication sharedApplication] keyWindow].bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
@skwashua
skwashua / gist:8093208
Last active January 1, 2016 04:39
iOS 7 "Frosted Glass" view with blur effect.
UIToolbar *blurringToolbar = [[UIToolbar alloc] initWithFrame:self.someView.bounds];
blurringToolbar.barStyle = UIBarStyleDefault;
blurringToolbar.translucent = YES;
blurringToolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.someView insertSubview:blurringToolbar atIndex:0];
UIBezierPath *myClippingPath = ...
CAShapeLayer *mask = [CAShapeLayer layer];
mask.path = myClippingPath.CGPath;
myView.layer.mask = mask;