Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An extension for Sparrow that takes advantage of GLKView's snapshot method to create UIImages of specific display objects.
//
// 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
//
// 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
You can’t perform that action at this time.