Skip to content

Instantly share code, notes, and snippets.

@Athosone
Created January 3, 2016 17:35
Show Gist options
  • Save Athosone/92ef254dd853c107ca45 to your computer and use it in GitHub Desktop.
Save Athosone/92ef254dd853c107ca45 to your computer and use it in GitHub Desktop.
+ (CGRect) screenFrame
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
return screenRect;
}
+ (UIImage *)convertViewToImage
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return capturedScreen;
}
+ (UIImage *)convertViewToImageWithView:(UIView *)view
{
CGRect rect = [view bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return capturedScreen;
}
+ (UIImageView *) performScreenshotAndBlur
{
UIImage * image = [self convertViewToImage];
static GPUImageiOSBlurFilter *_blurFilter;
UIImageView *bg = [[UIImageView alloc] initWithFrame:[HelpersClass screenFrame]];
_blurFilter = [[GPUImageiOSBlurFilter alloc] init];
_blurFilter.blurRadiusInPixels = 2.0;
UIImage *blurredSnapshotImage = [_blurFilter imageByFilteringImage:image];
[bg setImage:blurredSnapshotImage];
bg.alpha = 1.0;
// [[[[UIApplication sharedApplication] delegate] window] addSubview:bg];
return bg;
}
+ (UIImageView *) performScreenshotAndBlurForView:(UIView *)view
{
UIImage * image = [self convertViewToImageWithView:view];
static GPUImageiOSBlurFilter *_blurFilter;
UIImageView *bg = [[UIImageView alloc] initWithFrame:[HelpersClass screenFrame]];
_blurFilter = [[GPUImageiOSBlurFilter alloc] init];
_blurFilter.blurRadiusInPixels = 2.0;
UIImage *blurredSnapshotImage = [_blurFilter imageByFilteringImage:image];
[bg setImage:blurredSnapshotImage];
bg.alpha = 1.0;
// [[[[UIApplication sharedApplication] delegate] window] addSubview:bg];
return bg;
}
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0,newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment