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

In This Topic
    JPEGFormat Class
    In This Topic
    Represents a Joint Photographic Experts Group (JPEG) format object that can be used to export a MapView, MapFrame, or a Layout.
    Syntax
    public class JPEGFormat : ExportFormat 
    Public Class JPEGFormat 
       Inherits ExportFormat
    Remarks
    JPEG files are compressed image files. They support 24-bit color and are a popular choice for use on the web because a JPEG file size is often substantially smaller than many other image formats. However, the JPEG compression algorithm is lossy and is not recommended for many map images, as line drawings, and text or icon graphics become blurred by compression artifacts. Therefore, PNG is usually a superior format for map images. JPEGs can be generated with an accompanying world file for use as georeferenced raster data.
    Example
    ExportJPEG_Layout
    //This example demonstrates how to export a layout to JPEG.
    
    //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 ExportLayoutToJPEGExample
    {
      public static Task ExportLayoutToJPEGAsync(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 JPEG format with appropriate settings
        JPEGFormat JPEG = new JPEGFormat();
        JPEG.Resolution = 300;
        JPEG.OutputFileName = Path;
    
        return QueuedTask.Run(() =>
        {
                //Export Layout
                Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
                if (JPEG.ValidateOutputFilePath())
          {
            lyt.Export(JPEG);
          }
        });
      }
    }
    ExportJPEG_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to JPEG.
    
    //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 ExportMapFrameToJPEGExample
    {
      public static Task ExportMapFrameToJPEGAsync(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 JPEG format with appropriate settings
        JPEGFormat JPEG = new JPEGFormat();
        JPEG.HasWorldFile = true;
        JPEG.Resolution = 300;
        JPEG.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;
          if (JPEG.ValidateOutputFilePath())
          {
            mf.Export(JPEG);
          }
        });
      }
    }
    ExportJPEG_ActiveMap
    //This example demonstrates how to export the active mapview to JPEG.
    
    //Added references
    using ArcGIS.Desktop.Framework.Threading.Tasks;    //QueuedTask
    using ArcGIS.Desktop.Mapping;                      //MapView and Export formats
    
    public class ExportActiveMapToJPEGExample
    {
      public static Task ExportActiveMapToJPEGAsync(string Path)
      {
        return QueuedTask.Run(() =>
        {
                //Reference the active map view
                MapView mapv = MapView.Active;
    
                //Create JPEG format with appropriate settings
                JPEGFormat JPEG = new JPEGFormat();
          JPEG.Resolution = 300;
          JPEG.Height = 500;
          JPEG.Width = 800;
          JPEG.HasWorldFile = true;
          JPEG.OutputFileName = Path;
    
                //Export active map view
                if (JPEG.ValidateOutputFilePath())
          {
            mapv.Export(JPEG);
          }
        });
      }
    }
    JPEG_Constructor
    JPEGFormat JPEG = new JPEGFormat();
    Export a map frame to JPG
    //Export a map frame to JPG.
    
    //Create JPEG format with appropriate settings
    //BMP, EMF, EPS, GIF, PDF, PNG, SVG, TGA, and TFF formats are also available for export
    //at 2.x - JPEGFormat JPG = new JPEGFormat()
    //{
    //  HasWorldFile = true,
    //  Resolution = 300,
    //  OutputFileName = filePath,
    //  JPEGColorMode = JPEGColorMode.TwentyFourBitTrueColor,
    //  Height = 800,
    //  Width = 1200
    //};
    JPEGFormat JPG = new JPEGFormat()
    {
      HasWorldFile = true,
      Resolution = 300,
      OutputFileName = filePath,
      ColorMode = JPEGColorMode.TwentyFourBitTrueColor,
      Height = 800,
      Width = 1200
    };
    
    //Reference the map frame
    MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
    
    //Export on the worker thread
    await QueuedTask.Run(() =>
    {
      //Check to see if the path is valid and export
      if (JPG.ValidateOutputFilePath())
      {
        mf.Export(JPG);  //Export the map frame to JPG
      }
    });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Mapping.ExportFormat
          ArcGIS.Desktop.Mapping.JPEGFormat

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also