ArcObjects Library Reference (Carto)  

IMapServer.ExportMapImage Method

Generates an image of the map, based on the given map description, and writes the image to a specified file on disk. Supported file types are: 'bmp', 'jpg', 'tif', 'png'/'png8', 'png24', 'emf', 'ps', 'pdf', 'ai', 'gif', and 'svg'/'svgz'.

[Visual Basic .NET]
Public Function ExportMapImage ( _
    ByVal mapDesc As IMapDescription, _
    ByVal imageDesc As IImageDescription _
) As IMapImage
[C#]
public IMapImage ExportMapImage (
    IMapDescription mapDesc,
    IImageDescription imageDesc
);
[C++]
HRESULT ExportMapImage(
  IMapDescription* mapDesc,
  IImageDescription* imageDesc,
  IMapImage** MapImage
);
[C++]

Parameters

mapDesc [in]

  mapDesc is a parameter of type IMapDescription

imageDesc [in]

  imageDesc is a parameter of type IImageDescription

MapImage [out, retval]

  MapImage is a parameter of type IMapImage

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

Use ExportMapImage to retrieve a file (image or vector format) of the map.

The input parameter MapDescription contains properties describing the map (also known as the data frame). These include the map's Name, the MapArea, the SpatialReference , as well as collections of LayerDescription objects. Size, resolution and file format are determined by the ImageDescription, which includes ImageDisplay and ImageType objects.

ExportMapImage returns a MapImage object. MapExtent, MapScale and an array of VisibleLayers can be retrieved from the MapImage.

You can export the map to either a vector or an image type. This is specified by the ReturnType property of IImageType.

Setting the size and resolution of the output

Size and resolution are set in the ImageDisplay. Both Height and Width are required. The Height and Width properties of IImageResult are read-only and are not used to make changes. In order to control the size of an exported image, IMapServerInit2 contains two properties: MaxImageHeight and MaxImageWidth. The default value for these properties is 1024 pixels.

You should be careful when specifying a DeviceResolution to the ImageDisplay. This is merely used by the map service to determine map scale on the server, it does not define the resolution of the map image. Changing the DeviceResolution may lead to unintended changes in the map scale. For example, you export a map image to JPG. You specify an image of 400 pixels by 600 pixels with the DeviceResolution set at 96. The relative MapScale of the resulting image is around 54,000,000. Next, you increase the DeviceResolution to 300 while keeping the size constant. The MapScale of this result is about 205,000,000. The result may not be want you wanted if the map contains layers or labels that are scale-dependent. In order to to maintain the MapScale at around 1:54,000,000 you would need to export a larger image.

If you are exporting to PDF you will need to keep in mind that PDF exits in page space. Setting the Height and Width sets the dimensions of the PDF page. For example, you export a map image to PDF where the ImageDisplay Height is 400 and the Width is 500. The DeviceResolution is 100. The resulting PDF is 4 inches by 5 inches. Holding the Height and Width settings constant, as you increase the DeviceResolution the actual size of the PDF will get smaller. As you decrease the DeviceResolution the size of the PDF gets larger. This will also affect MapScale. If you wish the MapScale to stay constant you will need to increase (or decrease) the ImageDisplay Height and Width values as you increase (or decrease) the DeviceResolution.

DeviceResolution also affects the symbols is rendered. For example, two map images were generated using the same size (250x250), same extent but a different DeviceResolution. The first map image was created with a DeviceResolution of 96 and the second one with 200. You will notice the symbols size differences between those two images. Symbology size is defined using points (1 point = 1/72 inch) in the source map. To determine symbology size in a map, DeviceResolution is used to convert from points to pixels with the following equation:

Symbol Size in Points * (DeviceResolution/Number of Points in 1 inch)
 
In the map image with 96 DeviceResolution, a symbol size of 1 point will use 1.33 pixels (rounded down to 1 pixel) to render. In the map image with 200 DeviceResolution, a symbol size of 1 point will use 2.78 (rounded up to 3 pixels) to render.  As a result, the symbology appears larger in the map image created using a DeviceResolution of 200.

Image quality and image type of optimized MapServer

Miscellaneous

Exporting a map from a cached service does not generate map dynamically, instead it creates map using pre-cooked cache tiles.

Exporting a map is different than exporting a layout. Page space is an important component of ExportLayout. It exists for all map documents and the map services the documents are based on. This page space provides the default size of the exported layout (for best results you should use this default). Page space does not exist in ExportMapImage. Therefore, you will see differences in results when adjusting the Height, Width or DeviceResolution for a ExportMapImage as compared to making similar adjustments for ExportLayout.

Use IMapServerGeoTransformation when the image output from a map service is to be displayed in a coordinate system where the underlying geographic coordinate system is different than the underlying geographic coordinate system of the DefaultMapDescription.

[C#]

Example: exporting map for a given time

IMapTimeDescription pMapTimeDesc = pMapDesc as IMapTimeDescription;

ITime pTime = new TimeClass();
// date-time in YYYY/MM/DD hh:mm:ss format
pTime.SetFromTimeString(esriTimeStringFormat.esriTSFYearThruSecondWithSlash, "2000/01/01 09:00:00");

ITimeInstant pTimeInstant = new TimeInstantClass();
pTimeInstant.Time = pTime;
pTimeInstant.TimeReference = pMapTimeDesc.TimeReference;

pMapTimeDesc.TimeValue = pTimeInstant;

IImageDisplay pImgDisp = new ImageDisplayClass();
pImgDisp.DeviceResolution = 96;
pImgDisp.Height = 500;
pImgDisp.Width = 500;

IImageType pImgType = new ImageTypeClass();
pImgType.Format = esriImageFormat.esriImagePNG;
pImgType.ReturnType = esriImageReturnType.esriImageReturnURL;

IImageDescription pImageDesc = new ImageDescriptionClass();
pImageDesc.Display = pImgDisp;
pImageDesc.Type = pImgType;

IMapImage pMapImage = pMapServer.ExportMapImage(pMapDesc, pImageDesc);
Console.WriteLine(pMapImage.URL);

See Also

IMapServer Interface

.NET Related Topics

Managing application state | Map services