I've been trying to get a screenshot from a C++ program in MacOSX 10.8.4 and it's been impossible. I can't even get a single pixel. Is it even possible?
Can somebody help me? Or at least give me some clue or link.
I've been trying to get a screenshot from a C++ program in MacOSX 10.8.4 and it's been impossible. I can't even get a single pixel. Is it even possible?
Can somebody help me? Or at least give me some clue or link.
void captureScreen(){
CGImageRef image_ref = CGDisplayCreateImage(CGMainDisplayID());
CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
CFDataRef dataref = CGDataProviderCopyData(provider);
size_t width, height; width = CGImageGetWidth(image_ref);
height = CGImageGetHeight(image_ref);
size_t bpp = CGImageGetBitsPerPixel(image_ref) / 8;
uint8 *pixels = malloc(width * height * bpp);
memcpy(pixels, CFDataGetBytePtr(dataref), width * height * bpp);
CFRelease(dataref);
CGImageRelease(image_ref);
FILE *stream = fopen("/Users/robert/Desktop/screencap.raw", "w+");
fwrite(pixels, bpp, width * height, stream);
fclose(stream);
free(pixels);
}
If all you want is to grab an image of a window, try pressing the key sequence⌘+shift+3 will take a snapshot of the entire screen, and place the resulting image on your desktop.
Replacing 3 with 4 will allow you to interactively select a region of the screen.
Finally, pressing ⌘+shift+4, then space will allow you to select a window to capture.
This page nicely describes a lot of methods for capturing content on the screen.