SaveMapToImage()

Summary

Saves the contents of the map window to an image file.

Changes

Resolution, Alpha Channels, and Opacity options added to Version 5.0. TIFF and GIF image types added to Version 6.0/2012.

Syntax

SaveMapToImage(string map_name, string file_name, string type, array options)

Argument Contents
map_name The map to be saved, or null for the current map
file_name The path and file name of the image file to be created
type Type of image file: "JPEG", "BITMAP", "TIFF", "GIF", or "PNG" (not case sensitive)
Option Type Contents
Resolution Integer The number of dots per inch to use in the output. The default is the map window resolution.
Quality Integer Quality of the JPEG image. The higher the quality setting, the larger the resulting JPEG files. The default quality is 75.
Alpha Channels Array An array of two element subarrays, each of which must be a {macro_color, opacity_level} pair (PNG images only)
Opacity Integer The opacity level (from 255=completely opaque to 0=completely transparent) for all colors not specified in the Alpha Channel option (PNG images only)

Notes

  • The image file includes only the contents of the window, not the title, border, etc.

  • Attached legends will be included. Legends in separate windows can be saved with SaveLegendToImage().

  • The type is not case sensitive.

  • A common resolution for many monitors is 100 dpi, but you can specify a larger number, creating an image with greater number of pixels. The maximum for the Resolution option is around 300; the limit is your available video RAM.

  • JPEG is a lossy compression, meaning that the output image will not be identical to the original. There is a trade-off between the quality of the image file and its size. The quality value is a number between 1 and 100, where 100 is the highest quality image and 1 is the lowest. A quality value of 75 is recommended.

  • Opacity is the inverse of transparency. An opacity level of 255 indicates completely opaque (solid), and an opacity level of 0 indicates completely transparent (clear).

  • In the Alpha Channels option for PNG images, each subarray contains a color macro_color and its corresponding opacity opacity_level. The subarrays override the overall opacity set by the Opacity option. Colors are created with ColorRGB().

  • This function is preferable to using SaveMapToBitmap() or SaveMapToJPEG().

  • Make sure that the map has been redrawn to reflect any changes before calling SaveMapToImage(). The Quality option may force a redraw.

>Examples

SaveMapToImage("My Map", "c:\\images\\map1.jpg", "JPEG", {{"Quality", 70}} )
// Make white background of PNG be clear and rest of colors be about 80% opaque
background_color = ColorRGB(65535, 65535, 65535)
SaveMapToImage("My Map", "c:\\images\\map2.png", "PNG", {{"Opacity", 200}, {"Alpha Channels",{{background_color,0}}}} )

Error Codes

Error Type Meaning
Error Error writing to disk (e.g., out of disk space)
NotFound The specified map does not exist

See Also

Function Summary
SaveEditorToImage() Saves the contents of the editor window to an image file
SaveFigureToImage() Saves the contents of the figure window to an image file
SaveLayoutToImage() Saves the contents of the layout window to an image file
SaveLegendToImage() Saves a legend in a separate window to an image file