This document is archived and information here might be outdated.  Recommended version.


IMapServerLayout.ExportScaleBar Method (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference (Carto)  

IMapServerLayout.ExportScaleBar Method

Exports a scale bar to an image file. The client can create the scaleBar object and set its desired properties appropriately. If scaleBar is Nothing/Null, a default scale bar will be generated.

[Visual Basic .NET]
Public Function ExportScaleBar ( _
    ByVal Scalebar As IScaleBar, _
    ByVal mapDesc As IMapDescription, _
    ByVal pMapDisplay As IImageDisplay, _
    ByVal BackgroundColor As IColor, _
    ByVal imageDesc As IImageDescription _
) As IImageResult
[C#]
public IImageResult ExportScaleBar (
    IScaleBar Scalebar,
    IMapDescription mapDesc,
    IImageDisplay pMapDisplay,
    IColor BackgroundColor,
    IImageDescription imageDesc
);
[C++]
HRESULT ExportScaleBar(
  IScaleBar* Scalebar,
  IMapDescription* mapDesc,
  IImageDisplay* pMapDisplay,
  IColor* BackgroundColor,
  IImageDescription* imageDesc,
  IImageResult** ImageResult
);
[C++]

Parameters Scalebar [in]
Scalebar is a parameter of type IScaleBar mapDesc [in]
mapDesc is a parameter of type IMapDescription pMapDisplay [in]
pMapDisplay is a parameter of type IImageDisplay BackgroundColor [in]
BackgroundColor is a parameter of type IColor imageDesc [in]
imageDesc is a parameter of type IImageDescription ImageResult [out, retval]
ImageResult is a parameter of type IImageResult

Product Availability

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

Remarks

Use ExportScaleBar to retrieve the map's scale bar. To customize the scale bar pass in a ScaleBar object. If you pass in Nothing/Null for the input paramter ScaleBar, a default alternating scale bar is drawn. The scale is calculated according to the height and width of the the image (pMapDisplay). This ImageDisplay object refers to the map. Another ImageDisplay object will be used (as part of the imageDesc parameter) that refers to the Scale Bar image. A color background can be set for the ScaleBar swatch by using the backgroundColor parameter. If this is Nothing/Null a white background will be used. Use TransparentColor in IImageDisplay2 if you want the background to be transparent. Size, resolution and file format are determined by ImageDescription, which includes ImageDisplay and ImageType. ExportScaleBar returns an ImageResult object.

Use the height and width properties of IImageDisplay (as part of the imageDesc parameter) to set the proper size of the scalebar. Entering a 0 for either the height or the width for ExportScaleBar output results in an error.


 

[C#]

The following sample code shows how to export a default alternating scale bar. It assumes that you already have a valid MapServerLayout and MapDescription object, and that you are not working with a server context. However, if you are developing an ArcGIS for Server application using a server context, you should not use New to create local ArcObjects, but you should always create objects within the server by calling CreateObject on IServerContext.

IMapServerLayout mapServerLayout;
IMapDescription mapDesc;
// Make sure not to confuse input parameters mapDisplay and ImageDesc!

// Image description (used for the scale bar image to be generated)
// Image type
IImageType imageType=new ImageTypeClass();
imageType.Format=esriImageFormat.esriImageJPG;
imageType.ReturnType=esriImageReturnType.esriImageReturnMimeData;
// Image Display
IImageDisplay imageDisp=new ImageDisplayClass();
imageDisp.Height=40;
imageDisp.Width=400;
imageDisp.DeviceResolution=96;
// Image Description
IImageDescription imageDesc=new ImageDescriptionClass();
imageDesc.Type=imageType;
imageDesc.Display=imageDisp;

// Map Display (used to calculate scale)
IImageDisplay mapDisplay=new ImageDisplayClass();
mapDisplay.Height=500;
mapDisplay.Width=500;
mapDisplay.DeviceResolution=96;

// Export scale bar
IImageResult imageResult;
imageResult=mapServerLayout.ExportScaleBar(null, mapDesc, mapDisplay, null, imageDesc );

See Also

IMapServerLayout Interface