SaveImage()

Syntax

Result = SaveImage(#Image, Filename$ [, ImagePlugin [, Flags [, Depth]]])
Description
Saves the specified image to disk.

Parameters

#Image The image to save.
Filename$ The file to save to. If the filename does not include a full path, it is interpreted relative to the current directory.
ImagePlugin (optional) The format to save the image in. This can be one of the following values:
  #PB_ImagePlugin_BMP      : Save the image in BMP (default)
  #PB_ImagePlugin_JPEG     : Save the image in JPEG (UseJPEGImageEncoder() has to be used)
  #PB_ImagePlugin_JPEG2000 : Save the image in JPEG2000 (UseJPEG2000ImageEncoder() has to be used)
  #PB_ImagePlugin_PNG      : Save the image in PNG (UsePNGImageEncoder() has to be used)
Flags (optional) Optional parameters for the image plug-in. For now, only the quality setting is supported: a number from 0 (worse quality) to 10 (maximum quality). Only the JPEG and JPEG 2000 plugins currently support it (default quality is set to '7' if no flags are specified).

When an image is saved using palettized depth (1, 4 or 8), the following flag is available:
  #PB_Image_FloydSteinberg: Apply a Floyd-Steinberg dithering.
When a 32-bit image is saved in a lower depth (24-bit or lower) the following flags are available to change the color used to fill the transparent area:
  #PB_Image_WhiteAlphaBackground: the resulting image will use white color when transparent area is found (default)
  #PB_Image_BlackAlphaBackground: the resulting image will use black color when transparent area is found
Depth (optional) The depth in which to save the image. Valid values are 1, 4, 8, 24 and 32. The default value is the original image depth. For now, only BMP and PNG encoders support palletized image format (1, 4 or 8-bit).

Return value

Returns nonzero if the operation succeeded and zero if it failed.

Example

  UsePNGImageEncoder()
  
  If CreateImage(0, 33, 33)
    If StartDrawing(ImageOutput(0))
      DrawingMode(#PB_2DDrawing_Transparent)
        Box(0, 0, 33, 33, $FF0000) ; draw a blue box and save it as PNG image file below
      StopDrawing()
    EndIf
    file$ = SaveFileRequester("Select file to save", GetCurrentDirectory(), "*.png|*.png", 0)
    If file$
      If GetExtensionPart(file$) = ""
        file$ + ".png"  ; add the file extension if needed
      EndIf
      If SaveImage(0, file$, #PB_ImagePlugin_PNG)
        MessageRequester("File created", file$)
      Else
        MessageRequester("Error", "Failed to save file")
      EndIf
    EndIf
    FreeImage(0)
  EndIf

See Also

ImageDepth(), ImagePlugin library

Supported OS

All

<- ResizeImage() - Image Index - SetImageFrame() ->