If you don’t find, an alternative solution could be: use a external application to do it. For example: http://code.google.com/p/boxcutter/
I don’t know how to launch an external app, but it must be possible.
wow, i think this will be difficult, since i’m not sure that there is a good screen capture example for OF and windows.
that boxcutter app looks like it’s the closest thing. check out the boxcutter.cpp for a place to get started:
// Captures a screenshot from a region of the screen
// saves it to a file
bool capture_screen(const char *filename, int x, int y, int x2, int y2)
{
// normalize coordinates
normalize_coords(&x, &y, &x2, &y2);
int w = x2 - x;
int h = y2 - y;
// copy screen to bitmap
HDC screen_dc = GetDC(0);
HDC shot_dc = CreateCompatibleDC(screen_dc);
HBITMAP shot_bitmap = CreateCompatibleBitmap(screen_dc, w, h);
HGDIOBJ old_obj = SelectObject(shot_dc, shot_bitmap);
if (!BitBlt(shot_dc, 0, 0, w, h, screen_dc, x, y, SRCCOPY)) {
printf("error: BitBlt failed\n");
return false;
}
// save bitmap to file
bool ret = save_bitmap_file(shot_bitmap, shot_dc, filename);
DeleteDC(shot_dc);
DeleteDC(screen_dc);
SelectObject(shot_dc, old_obj);
return ret;
}
instead of this line:
bool ret = save_bitmap_file(shot_bitmap, shot_dc, filename);
you’re going to want to load the data into an ofImage and return it.
kylemcdonald, your replies enlarge my coding vision
gavinh, this afternoon I discovered how to launch an external program, so I can tell you more now.
If you put boxcutter.exe into your bin folder, you can use this code to capture the screen:
string fileName = "screenshot.png";
int x = 10;
int y = 30;
int w = 200;
int h = 150;
char cmd[300];
sprintf(cmd, "boxcutter -c %d,%d,%d,%d data\\%s", x, y, w, h, fileName.c_str());
system(cmd);
Probably not the best way to do it, but it work.
P.S: you can either install boxcutter in any folder on your hard drive, and add this folder to your path environment variable.
unfortunately i think gavinh is trying to get capture in realtime, something like the xcode example that zach posted, rather than just grabbing a single screenshot so constantly saving+compressing images to pngs might be too slow.