SDL Saving window as BMP

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-16 18:03:45

问题


I am writing a program in SDL and C and I want to be able to save the window as an image.

This is my code:

screen = SDL_GetWindowSurface(win);
SDL_SaveBMP(screen,"screen");

But when I execute it I get:

Segmentation Fault

From other sources I gather that its about pointers and memory access. Any help?


回答1:


Call SDL_LockSurface on a window surface before saving bitmap, and SDL_UnlockSurface after that.




回答2:


    SDL_Surface *sshot = SDL_CreateRGBSurface(0, 750, 750, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
    SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);
    SDL_SaveBMP(sshot, "screenshot.bmp");
    SDL_FreeSurface(sshot); 


来源:https://stackoverflow.com/questions/30157164/sdl-saving-window-as-bmp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!