SDL School

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

fileThe path of the file.

Return value

A new surface, or NULL on failure. SDL_GetError gives the reason.

Example

Load an image
SDL_Surface *surface = SDL_LoadPNG(path);

See this code run in Load an image. Download the full program (.zip)

Notes

In SDL2

SDL2 has no such function. Use IMG_Load from SDL_image, or SDL_LoadBMP for a BMP file.

See also