/
UIImage+Frank.m
59 lines (48 loc) · 1.44 KB
/
UIImage+Frank.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// UIImage+Frank.m
// Frank
//
// Created by Brian King on 2/24/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "UIImage+Frank.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage(Frank)
+ (UIImage *) imageFromApplication:(BOOL)allWindows
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(keyWindow.bounds.size);
if (allWindows)
{
for (UIWindow *w in [[UIApplication sharedApplication] windows])
{
[w.layer renderInContext:UIGraphicsGetCurrentContext()];
}
}
else
{
[keyWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (UIImage *)imageCropedToFrame:(CGRect)cropFrame
{
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], cropFrame);
UIImage *result = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return result;
}
- (UIImage *)imageMaskedAtFrame:(CGRect)maskFrame
{
CGRect imageFrame = CGRectMake(0, 0, self.size.width, self.size.height);
UIGraphicsBeginImageContext(self.size);
[self drawInRect:imageFrame];
[[UIColor blackColor] set];
UIRectFill(maskFrame);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
@end