imgSave function image

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

Save an SDL_Surface into an image file.

If the file already exists, it will be overwritten.

For formats that accept a quality, a default quality of 90 will be used.

\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.4.0.

\sa IMG_SaveTyped_IO \sa IMG_SaveAVIF \sa IMG_SaveBMP \sa IMG_SaveGIF \sa IMG_SaveJPG \sa IMG_SavePNG \sa IMG_SaveTGA \sa IMG_SaveWEBP

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

Implementation

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