Skip to content

Instantly share code, notes, and snippets.

@nek023
Created March 2, 2013 09:23
Show Gist options
  • Save nek023/5070280 to your computer and use it in GitHub Desktop.
Save nek023/5070280 to your computer and use it in GitHub Desktop.
@interface NSImage (PNGRepresentation)
- (NSData *)PNGRepresentation;
@end
#import "NSImage+PNGRepresentation.h"
@implementation NSImage (PNGRepresentation)
- (NSData *)PNGRepresentation
{
[self lockFocus];
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, self.size.width, self.size.height)];
[self unlockFocus];
return [bitmapImageRep representationUsingType:NSPNGFileType properties:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment