imgSavePng function

bool imgSavePng(
  1. Pointer<SdlSurface> surface,
  2. String? file
)

Save an SDL_Surface into a PNG image file.

If the file already exists, it will be overwritten.

\param surface the SDL surface to save. \param file path on the filesystem to write new file to. \returns true on success or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL_image 3.0.0.

\sa IMG_SavePNG_IO

extern SDL_DECLSPEC bool SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *file)

Implementation

bool imgSavePng(Pointer<SdlSurface> surface, String? file) {
  final imgSavePngLookupFunction = libSdl3Image.lookupFunction<
      Uint8 Function(Pointer<SdlSurface> surface, Pointer<Utf8> file),
      int Function(
          Pointer<SdlSurface> surface, Pointer<Utf8> file)>('IMG_SavePNG');
  final filePointer = file != null ? file.toNativeUtf8() : nullptr;
  final result = imgSavePngLookupFunction(surface, filePointer) == 1;
  calloc.free(filePointer);
  return result;
}