Permalink
Browse files

Refactoring view image capture code

Conflicts:

	lib/cocoahttpserver
  • Loading branch information...
1 parent 11c0432 commit 9ffb47f5bf731bf9ccf4346ae9b85c9101cbdf9f @moredip committed Jul 26, 2012
Showing with 48 additions and 14 deletions.
  1. +4 −14 src/UIImage+Frank.m
  2. +16 −0 src/UIView+ImageCapture.h
  3. +28 −0 src/UIView+ImageCapture.m
View
@@ -7,7 +7,8 @@
//
#import "UIImage+Frank.h"
-#import <QuartzCore/QuartzCore.h>
+
+#import "UIView+ImageCapture.h"
@implementation UIImage(Frank)
@@ -16,21 +17,10 @@ + (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()];
- }
- }
+ return [UIView captureImageOfSize:keyWindow.bounds.size fromViews:[[UIApplication sharedApplication] windows]];
else
- {
- [keyWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
- }
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
+ return [keyWindow captureImage];
}
- (UIImage *)imageCropedToFrame:(CGRect)cropFrame
@@ -0,0 +1,16 @@
+//
+// UIView+ImageCapture.h
+// Frank
+//
+// Created by Pete Hodgson on 7/26/12.
+// Copyright (c) 2012 Thoughtworks. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface UIView (ImageCapture)
+
++ (UIImage *) captureImageOfSize:(CGSize)size fromViews:(NSArray *)views;
+- (UIImage *) captureImage;
+
+@end
@@ -0,0 +1,28 @@
+//
+// UIView+ImageCapture.m
+// Frank
+//
+// Created by Pete Hodgson on 7/26/12.
+// Copyright (c) 2012 Thoughtworks. All rights reserved.
+//
+
+#import "UIView+ImageCapture.h"
+#import <QuartzCore/QuartzCore.h>
+
+@implementation UIView (ImageCapture)
+
++ (UIImage *) captureImageOfSize:(CGSize)size fromViews:(NSArray *)views {
+ UIGraphicsBeginImageContext(size);
+ for (UIView *view in views) {
+ [view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ }
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return image;
+}
+
+- (UIImage *) captureImage{
+ return [UIView captureImageOfSize:self.bounds.size fromViews:[NSArray arrayWithObject:self]];
+}
+
+@end

0 comments on commit 9ffb47f

Please sign in to comment.