# How to convert a SDL window to a SDL surface? SDL 2

I am trying to make a paint program and there is a sdl function called IMG_SavePNG() which requires a surface and destination file. How can I turn what I see in the window to a surface?

• I haven't used SDL in a very long time however, since what your asking is equivalent to taking a screenshot, just get the backbuffers SDL Surface and pass it to your IMG_SavePNG(); – Grey Jan 30 '14 at 17:12
• @Grey Can you explain? – saloomi2012 Jan 30 '14 at 18:15
• Answered your question. Let me know if it works. – Grey Jan 30 '14 at 18:31
• You can use SDL_GetWindowSurface() to get a surface from the window. See this answer: stackoverflow.com/a/20233470/1212968 – Lysol Jan 30 '14 at 20:28
• @Grey uh there is no answer? – saloomi2012 Jan 31 '14 at 1:14

To achieve this in SDL, you need to use the SDL_GetWindowSurface() funcion. This function will return the surface associated with the window. You can then pass the surface to the IMG_SavePNG function to take a screenshot.