SAVEIMAGE

Purpose:

Saves an image to  BMP, GIF, JPEG, PNG, TIF and other image file formats.

Syntax:

SAVEIMAGE("filename", "format", "pixformat", series, overwrite)

"filename"

-

A string, the name of the target image file.

"format"

-

Optional. A string, the destination image file format. Defaults to the source file extension if omitted or empty. Supports the following formats:

"bmp"

:

Windows bitmap format

"dng", "adng"

:

Adobe Digital Negative format

"dds"

:

DirectDraw Surface

"gif"

:

Graphics Interchange Format

"heif"

:

High Efficiency Image File

"ico"

:

Windows Icon Format

"jpg", "jpeg"

:

Joint Photographic Experts Group Format

"tif", "tiff"

:

Tagged Image File Format

"webp"

:

Google raster file format

"wmp"

:

Windows Media Player format

"pixformat"

-

Optional. A string, the destination image pixel format. Defaults to "PBGRA32" (32-bit premultiplied BGRA) if omitted or empty. Supports the following pixel formats:

"Gray8"

:

8-bit grayscale (single channel, 256 shades)

"Alpha8"

:

8-bit alpha-only (opacity channel)

"Indexed8"

:

8-bit indexed color (palette lookup)

"Gray16"

:

16-bit grayscale (single channel)

"BGR555"

:

16-bit packed BGR (5-5-5 bits)

"BGR565"

:

16-bit packed BGR (5-6-5 bits)

"BGRA5551"

:

16-bit packed BGRA (5-5-5-1 bits)  

"BGR24"

:

24-bit BGR (8 bits per channel)

"RGB24"

:

24-bit RGB (8 bits per channel)

"BGR32"

:

32-bit BGR (8 bits per channel + padding)

"BGRA32"

:

32-bit BGRA (8 bits per channel)

"PBGRA32"

:

32-bit premultiplied BGRA (8 bits per channel)

"RGBA32"

:

32-bit RGBA (8 bits per channel)

"PRGBA32"

:

32-bit premultiplied RGBA (8 bits per channel)

"CMYK32"

:

32-bit CMYK (8 bits per channel)

"RGB48"

:

48-bit RGB (16 bits per channel)

"BGR48"

:

48-bit BGR (16 bits per channel)

"RGBA64"

:

64-bit RGBA (16 bits per channel)

"PRGBA64"

:

64-bit premultiplied RGBA (16 bits per channel)

"BGRA64"

:

64-bit BGRA (16 bits per channel)

"PBGRA64"

:

64-bit premultiplied BGRA (16 bits per channel)

"RGB96Float"

:

96-bit RGB float (32-bit float per channel)

"RGBA128Float"

:

128-bit RGBA float (32-bit float per channel)

"PRGBA128Float"

:

128-bit premultiplied RGBA float

"RGB128Float"

:

128-bit RGB float (32-bit float per channel)

"Gray32Float"

:

32-bit grayscale float

"Gray16Half"

:

16-bit grayscale half-float

"Gray32Fixed"

:

32-bit grayscale fixed-point

"Y8"

:

8-bit Y (luma) component (YCbCr)

"Cb8"

:

8-bit Cb (blue chroma difference)

"Cr8"

:

8-bit Cr (red chroma difference)

series

-

Optional. A series or window, the image to save. Defaults to the current window.

overwrite

-

Optional. An integer, the overwrite mode:

0:

prompt before overwriting file (default)

1:

overwrite file if it exists without prompting

2:

cancel if file exists

 

Returns:

An integer, 1 if successful, < 0 if failure.

Example:

W1: readimage(gethome + "data\mandrill.bmp")

saveimage(getmiscpath(1, 1) + "mandrill.png", w1, 1);

W2: readimage(getmiscpath(1, 1) + "mandrill.png")

 

W1 reads and displays the bitmap image file "mandrill.bmp".

 

SAVEIMAGE saves the image as a PNG file as determined by the "png" file extension. The existing file, if any, is overwritten.

 

W2 loads the PNG file. The image is the same as W1.

 

PNG Image

Example:

W3: readimage(gethome + "data\mandrill.bmp")

saveimage(getmiscpath(1, 1) + "mandrill.tif", "", "Gray8", w3, 1);

W4: readimage(getmiscpath(1, 1) + "mandrill.tif", "Gray8")

 

Grayscale TIFF Image

Same as above except, the image is saved as an 8-bit (0-255) grayscale TIFF file. Since READIMAGE normally returns a 24-bit RGBIMAGE, the pixel format is specified as "Gray8" to obtain a 0-255 grayscale image.

Example:

W3: spline2(randn(10), 10);setplottype(3);turbo

saveimage(getmiscpath(1, 1) + "density.png", w3, 1);

W4: readimage(getmiscpath(1, 1) + "density.png")

 

W3 creates a density plot by 2D cubic spline interpolation of a 10x10 random matrix, The resulting image is 91x91 and shaded using the TURBO color scheme.

 

SAVEIMAGE saves the density plot as a JPG file. The existing file if any, is overwritten.

 

W4 loads the JPG file. The image is the same as W3.

Remarks:

SAVEIMAGE saves an image from a window or series to a variety of image file formats.

 

By default, the type of saved image is determined by the filename extension. Current supported extensions include BMP, GIF, JPG, PNG and TIF.

 

See READIMAGE to load an image file.

See Also:

GETRGB

IMAGE24

READIMAGE

RGBIMAGE

SETASPECT

WRITEBMP