| Index | Submit class | Submit snippet | Submission feed | List |

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:


Comments

Name

Website

Do you hate spammers? (Answer "Yes")