Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ofPoint ofGetGlobalMousePosition() {
- #ifdef TARGET_OSX
- Point mouse;
- GetGlobalMouse(&mouse);
- return ofPoint(mouse.h, mouse.v);
- #endif
- }
- void ofGrabGlobalScreen(ofImage& img, ofRectangle& region) {
- region.width = MAX((int) region.width, 1);
- region.height = MAX((int) region.height, 1);
- #ifdef TARGET_OSX
- static int bytesPerPixel = 4;
- img.allocate(region.width, region.height, OF_IMAGE_COLOR_ALPHA);
- CGImageRef cgImage = CGWindowListCreateImage(
- CGRectMake(region.x, region.y, region.width, region.height),
- kCGWindowListOptionOnScreenOnly,
- kCGNullWindowID,
- kCGWindowImageDefault);
- CGContextRef spriteContext = CGBitmapContextCreate(
- img.getPixels(), region.width, region.height,
- CGImageGetBitsPerComponent(cgImage),
- region.width * bytesPerPixel,
- CGImageGetColorSpace(cgImage),
- kCGImageAlphaPremultipliedLast);
- CGContextDrawImage(spriteContext, CGRectMake(0, 0, (CGFloat) region.width, (CGFloat) region.height), cgImage);
- CGContextRelease(spriteContext);
- CGImageRelease(cgImage);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment