Skip to content

Instantly share code, notes, and snippets.

@pilotmoon
Created August 6, 2010 14:26
Show Gist options
  • Save pilotmoon/511388 to your computer and use it in GitHub Desktop.
Save pilotmoon/511388 to your computer and use it in GitHub Desktop.
- (NSImage *)blankImageOfSize:(NSSize)size;
{
NSBitmapImageRep *rep=[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:size.width
pixelsHigh:size.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];
// blank the image
unsigned char *data=[rep bitmapData];
NSUInteger count=[rep bytesPerPlane];
memset(data, 0, count);
NSImage *img=[[NSImage alloc] initWithSize:size];
[img addRepresentation:rep];
return img;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment