ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / PNGFormat Class
Members Example

In This Topic
    PNGFormat Class
    In This Topic
    Represents a Portable Network Graphics (PNG) object that can be used to export a MapView, MapFrame, or a Layout.
    Syntax
    public class PNGFormat : ExportFormat 
    Public Class PNGFormat 
       Inherits ExportFormat
    Remarks
    PNG is a versatile raster format that can display in web browsers and inserted into other documents. It supports high-bit-depth color and uses a lossless compression. For maps, PNG is often the best raster format, since the lossless compression keeps text and line work legible by preventing the compression artifacts that can occur in JPEG format. PNGs can be generated with an accompanying world file for use as georeferenced raster data.
    Example
    ExportPNG_Layout
    //This example demonstrates how to export a layout to PNG.
    
    //Added references
    using ArcGIS.Desktop.Core;                         //Project
    using ArcGIS.Desktop.Layouts;                      //Layout classes
    using ArcGIS.Desktop.Framework.Threading.Tasks;    //QueuedTask
    using ArcGIS.Desktop.Mapping;                      //Export formats
    
    public class ExportLayoutToPNGExample
    {
      public static Task ExportLayoutToPNGAsync(string LayoutName, string Path)
      {
        //Reference a layoutitem in a project by name
        LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
        if (layoutItem == null)
          return Task.FromResult<Layout>(null);
    
        //Create PNG format with appropriate settings
        PNGFormat PNG = new PNGFormat();
        PNG.Resolution = 300;
        PNG.OutputFileName = Path;
    
        return QueuedTask.Run(() =>
        {
                //Export Layout
                Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
                if (PNG.ValidateOutputFilePath())
          {
            lyt.Export(PNG);
          }
        });
      }
    }
    ExportPNG_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to PNG.
    
    //Added references
    using ArcGIS.Desktop.Core;                         //Project
    using ArcGIS.Desktop.Layouts;                      //Layout classes
    using ArcGIS.Desktop.Framework.Threading.Tasks;    //QueuedTask
    using ArcGIS.Desktop.Mapping;                      //Export formats
    
    public class ExportMapFrameToPNGExample
    {
      public static Task ExportMapFrameToPNGAsync(string LayoutName, string MFName, string Path)
      {
        //Reference a layoutitem in a project by name
        LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
        if (layoutItem == null)
          return Task.FromResult<Layout>(null);
    
        //Create PNG format with appropriate settings
        PNGFormat PNG = new PNGFormat();
        PNG.Resolution = 300;
        PNG.OutputFileName = Path;
    
        return QueuedTask.Run(() =>
        {
                //Export MapFrame
                Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
                MapFrame mf = lyt.FindElement(MFName) as MapFrame;
          PNG.OutputFileName = Path;
          if (PNG.ValidateOutputFilePath())
          {
            mf.Export(PNG);
          }
        });
      }
    }
    ExportPNG_ActiveMap
    //This example demonstrates how to export the active mapview to PNG.
    
    //Added references
    using ArcGIS.Desktop.Framework.Threading.Tasks;    //QueuedTask
    using ArcGIS.Desktop.Mapping;                      //MapView and Export formats
    
    public class ExportActiveMapToPNGExample
    {
      public static Task ExportActiveMapToPNGAsync(string Path)
      {
        return QueuedTask.Run(() =>
        {
                //Reference the active map view
                MapView mapv = MapView.Active;
    
                //Create PNG format with appropriate settings
                PNGFormat PNG = new PNGFormat();
          PNG.Resolution = 300;
          PNG.Height = 500;
          PNG.Width = 800;
          PNG.OutputFileName = Path;
    
                //Export active map view
                if (PNG.ValidateOutputFilePath())
          {
            mapv.Export(PNG);
          }
        });
      }
    }
    PNG_Constructor
    PNGFormat PNG = new PNGFormat();
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Mapping.ExportFormat
          ArcGIS.Desktop.Mapping.PNGFormat

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also