SDL_LoadPNG_IO(3)
π SDL_LoadPNG_IO π
okay bestie, so this one lives in the SDL3 FUNCTIONS part of the manual, and it's literally the glow-up you need when you've got a PNG chillin' in an SDL data stream and you want it to become a surface. no cap. π¦
β¨ NAME β¨
SDL_LoadPNG_IO β load a PNG image from a seekable SDL data stream. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
SDL_Surface * SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio);
like, that's it. that's the whole function signature. slay. π
π DESCRIPTION π
so the tea is: this is a convenience function for loading images from trusted sources. that part matters, bestie. if you're out here wanting to load arbitrary images β like, random stuff from the wild internet β you should be using libpng or another image loading library that was actually designed with security in mind. this one was not. i'm being so serious rn. π«Ά
the new surface it hands you? yeah, you must free it with SDL_DestroySurface(). not doing so will result in a memory leak, which is giving "my laptop fan sounds like a jet engine" energy. don't do that to yourself. π
π§ FUNCTION PARAMETERS π§
srcβ the data stream for the surface. it's the stream, it's the source, it's the moment. βcloseioβ if this istrue, it callsSDL_CloseIO()onsrcbefore returning, and it does this even in the case of an error. so like, it's a responsible queen that cleans up after herself no matter how things went. π
π RETURN VALUE π
returns a pointer to a brand new SDL_Surface structure, or NULL on failure β and if you get NULL, go call SDL_GetError() for more info. it will tell you what went wrong, i promise. π₯
π THREAD SAFETY π
it is safe to call this function from any thread. go wild, multitask, live your main character life. β¨
π AVAILABILITY π
this function has been available since SDL 3.4.0. so if you're on something older, it's not you, it's the version. π
π SEE ALSO π
SDL_DestroySurface(3)β the one you call afterwards, remember? free the surface!!SDL_LoadPNG(3)SDL_SavePNG_IO(3)
real talk though: trusted sources only. libpng exists for a reason and it's not to be ignored. π
and that's the page, bestie!! brought to you by Simple Directmedia Layer, running the SDL 3.4.18 era, and stamped with the SDL_LoadPNG_IO(3) energy. go load a PNG, destroy a surface, hydrate, and slay the day away. ππ
π¦β¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms