API reference / Images and textures
SDL_LoadPNG
Function, SDL3
Loads a PNG file into a surface, an image in main memory.
Declaration
#include <SDL3/SDL.h>
SDL_Surface * SDL_LoadPNG(const char *file);Parameters
file | The path of the file. |
Return value
A new surface, or NULL on failure. SDL_GetError gives the reason.
Example
SDL_Surface *surface = SDL_LoadPNG(path);See this code run in Load an image. Download the full program (.zip)
Notes
- Free the surface with
SDL_DestroySurface. - This function is new in SDL 3.4.
In SDL2
SDL2 has no such function. Use IMG_Load from SDL_image, or SDL_LoadBMP for a BMP file.