Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created August 21, 2013 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shilo/6291619 to your computer and use it in GitHub Desktop.
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.
//
// 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