Created
August 21, 2013 08:06
-
-
Save Shilo/6291619 to your computer and use it in GitHub Desktop.
An extension for Sparrow that takes advantage of GLKView's snapshot method to create UIImages of specific display objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SPDisplayObject+Snapshot.h | |
// Sparrow 2.X | |
// | |
// Created by Shilo White on 8/20/13. | |
// | |
// | |
#import "SPDisplayObject.h" | |
@interface SPDisplayObject (Snapshot) | |
@property (nonatomic, readonly) UIImage *snapshot; | |
- (UIImage *)snapshotWithStageColor:(uint)stageColor; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SPDisplayObject+Snapshot.m | |
// Sparrow 2.X | |
// | |
// Created by Shilo White on 8/20/13. | |
// | |
// | |
#import "SPDisplayObject+Snapshot.h" | |
@implementation SPDisplayObject (Snapshot) | |
- (UIImage *)snapshot | |
{ | |
UIImage *stageSnapshot = [((GLKView *)Sparrow.currentController.view) snapshot]; | |
SPRectangle *bounds = [self boundsInSpace:Sparrow.stage]; | |
CGImageRef imageRef = CGImageCreateWithImageInRect(stageSnapshot.CGImage, CGRectMake(bounds.x, bounds.y, bounds.width, bounds.height)); | |
UIImage *snapshot = [UIImage imageWithCGImage:imageRef]; | |
CGImageRelease(imageRef); | |
return snapshot; | |
} | |
- (UIImage *)snapshotWithStageColor:(uint)stageColor | |
{ | |
uint oldStageColor = Sparrow.stage.color; | |
Sparrow.stage.color = stageColor; | |
UIImage *snapshot = [self snapshot]; | |
Sparrow.stage.color = oldStageColor; | |
return snapshot; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment