SDL_Surface* ScreenShot(SDL_Window*w,SDL_Renderer*r,SDL_Rect*rect)
{
SDL_Rect real_rect;
Uint32 format;
int bpp;
Uint32 rmask,gmask,bmask,amask;
char*pixels;
int pitch;
if ((!w) || (!r)) return NULL;
if (!rect)
{
real_rect.x=0;
real_rect.y=0;
SDL_GetWindowSize(w,&real_rect.w,&real_rect.h);
}
else real_rect=*rect;
format=SDL_GetWindowPixelFormat(w);
SDL_PixelFormatEnumToMasks(format,&bpp,&rmask,&gmask,&bmask,&amask);
pitch=SDL_BYTESPERPIXEL(format)*(real_rect.w);
pixels=(char*)malloc(pitch*(real_rect.h)*sizeof (char));
SDL_RenderReadPixels(r,&real_rect,format,(void*)pixels,pitch);
return SDL_CreateRGBSurfaceFrom((void*)pixels,real_rect.w,real_rect.h,bpp,pitch,rmask,gmask,bmask,amask);
}
//拿去,不用谢