Hi All,
Ok , I did some progress and use this code , I can get ScreenShoot of my
desktop when I use depth 32, but When I change it into depth 24, it dosn’t
work , any idea?
I just change this line:
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width, at.height,
24, img->red_mask, img->green_mask, img->blue_mask, 0);
#include <assert.h>
#include <SDL/SDL.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void screenshot(const char *filename)
{
Display *disp = XOpenDisplay(NULL);
Window win = XDefaultRootWindow(disp);
XWindowAttributes at;
XGetWindowAttributes(disp, win, &at);
XImage *img = XGetImage(disp, win, at.x, at.y, at.width, at.height,
XAllPlanes(), ZPixmap);
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width,
at.height, 32, img->red_mask, img->green_mask, img->blue_mask, 0);
int x, y;
SDL_LockSurface(tmp);
for (y = 0; y < at.height; y++) {
for (x = 0; x < at.width; x++) {
((unsigned *)tmp->pixels)[x + y * at.width] = XGetPixel(img, x,
y);
}
}
SDL_UnlockSurface(tmp);
SDL_SaveBMP(tmp, filename);
SDL_FreeSurface(tmp);
XCloseDisplay(disp);
}
int main(int argc, char *argv[])
{
assert(argc > 1);
SDL_Init(SDL_INIT_VIDEO);
screenshot(argv[1]);
return 0;
}
Best Regards,
Gadi