Snippet #7
Language: Objective-C, Author: Michele Balistreri
License: Public domain
This code access to the low-level framebuffer and can be used for example to take screenshots. This code can be easily adapted to Intel, where the alpha channel should be the last.
CGDirectDisplayID display = CGMainDisplayID(); size_t width = CGDisplayPixelsWide(display); size_t height = CGDisplayPixelsHigh(display); UInt8 *frameBuffer = CGDisplayBaseAddress(display); NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&frameBuffer pixelsWide:width pixelsHigh:height bitsPerSample:CGDisplayBitsPerSample(display) samplesPerPixel:CGDisplaySamplesPerPixel(display) hasAlpha:NO isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaFirstBitmapFormat bytesPerRow:CGDisplayBytesPerRow(display) bitsPerPixel:CGDisplayBitsPerPixel(display)];
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.5 PPC
Comments
Comment feed
