Created
March 1, 2013 08:43
-
-
Save robert-wallis/5063309 to your computer and use it in GitHub Desktop.
Capture the raw screen pixels in OSX.
Then saves to a file for debugging.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
I like your version @kwhat https://github.com/kwhat/libscreencapture/blob/master/src/darwin/screen_capture.c awesome you are making a multi-platform library!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anyone looking to capture part of the screen, replace
CGImageRef image_ref = CGDisplayCreateImage(CGMainDisplayID());
with the following: