Click or drag to resize
Code Example - ArcGISDynamicMapServiceLayerImageFormat

Shows changing the return ImageFormat for ArcGISDynamicMapServiceLayer and how that appears visually in the Map.

Code Example
ArcGISDynamic Map Service Layer Image Format

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="ArcGISDynamicMapServiceLayerImageFormat.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" 
        Title="MainWindow" Height="600" Width="800">

    <Grid>
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">

                <!-- Add a MapView Control. -->
                <esri:MapView x:Name="MapView1" Width="637" Height="568" VerticalAlignment="Top">
                    <!-- Add a Map. -->
                    <esri:Map  x:Name="Map1" >

                        <!-- Add a backdrop ArcGISTiledMapServiceLayer. -->
                        <esri:ArcGISTiledMapServiceLayer ID="World_Light_Gray_Base" 
                              ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"/>

                        <!-- Add an ArcGISDynamicMapServiceLayer. This will be the one that has the ImageFormat modified. -->
                        <esri:ArcGISDynamicMapServiceLayer ID="USA_1990-2000_Population_Change" 
                              ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_1990-2000_Population_Change/MapServer"/>
                    </esri:Map>
                </esri:MapView>


                <TextBlock Width="10"/>
                <StackPanel Orientation="Vertical">
                    <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Pick an ImageFormat" 
                               VerticalAlignment="Top" Height="20"/>

                    <!-- This is the ListBox that will have the various ImageFormat Enumerations available. -->
                    <ListBox x:Name="ListBox1" VerticalAlignment="Top" Width="120" Height="300"
                             SelectionChanged="ListBox1_SelectionChanged_1"/>

                </StackPanel>
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "ArcGISDynamicMapServiceLayerImageFormat.MainWindow" to be just "MainWindow".

namespace ArcGISDynamicMapServiceLayerImageFormat
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            // This call is required by the designer.
            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.

            //// Set the initial extent of the Map using the InitialViewpoint Property.
            //Map1.InitialViewpoint = new Esri.ArcGISRuntime.Geometry.Envelope(-14811263, 296658, -5960159, 7921904,
            //                                                      Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator);

            // Create a Geometry based on an Envelope set to a particular extent of the Americas using a WebMercator Spatial Reference. 
            Esri.ArcGISRuntime.Geometry.Geometry myGeometry = new Esri.ArcGISRuntime.Geometry.Envelope(-14811263, 296658, -5960159, 7921904, Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator);

            // Set the initial extent of the Map using the InitialViewpoint Property to that of our Geometry.
            Map1.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myGeometry);
            // Call our custom 'async' function to display information about the ArcGISDynamicMapSericeLayer that was added in XAML.
            Init();
        }

        public async void Init()
        {
            // Get the ArcGISDynamicMapServiceLayer by it's ID value.        
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = null;
            myArcGISDynamicMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)MapView1.Map.Layers["USA_1990-2000_Population_Change"];

            // Initialize the ArcGISDynamicMapServiceLayer which allows for obtain various Property information.
            await myArcGISDynamicMapServiceLayer.InitializeAsync();

            // Get the MapServiceInfo details about the ArcGISDynamicMapServiceLayer.
            Esri.ArcGISRuntime.ArcGISServices.MapServiceInfo myMapServiceInfo = myArcGISDynamicMapServiceLayer.ServiceInfo;

            // Add all of the supported ImageFormat types for this ArcGISDynamicMapServiceLayer into the ListBox.
            // NOTE: Depending the service used, the number of supported ImageFormats could be different.
            // NOTE #2: The background color for an ArcGISDynamicMapServiceLayer will always be transparent when the ImageFormat 
            // is set to use a lossless data compression such as PNG. JPG is considered a lossy data compression and as such will 
            // not show the background of the layer to be transparent, meaning it will not drape well over other background layers.
            System.Collections.Generic.IReadOnlyList<Esri.ArcGISRuntime.ArcGISServices.ImageFormat> myIReadOnlyListOfImageFormat = null;
            myIReadOnlyListOfImageFormat = myMapServiceInfo.SupportedImageFormatTypes;
            foreach (var oneImageFormat in myIReadOnlyListOfImageFormat)
            {
                ListBox1.Items.Add(oneImageFormat);
            }
        }

        private void ListBox1_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            // Get the ArcGISDynamicMapServiceLayer.
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer theArcGISDynamicMapServiceLayer = null;
            theArcGISDynamicMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)(Map1.Layers["USA_1990-2000_Population_Change"]);

            // Get the ImageFormat selection from the ListBox.
            Esri.ArcGISRuntime.ArcGISServices.ImageFormat theSelection;
            theSelection = (Esri.ArcGISRuntime.ArcGISServices.ImageFormat)ListBox1.SelectedItem;

            // Set the ImageFormat from the user selection.
            theArcGISDynamicMapServiceLayer.ImageFormat = theSelection;

            // Refresh the ArcGISDynamicMapServiceLayer in the Map.
            theArcGISDynamicMapServiceLayer.Invalidate();
        }
    }
}