ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / JPEGFormat Class / HasWorldFile Property
Example

In This Topic
    HasWorldFile Property (JPEGFormat)
    In This Topic
    Gets or sets if a georeferenced world file will be created.
    Syntax
    public bool HasWorldFile {get; set;}
    Public Property HasWorldFile As Boolean
    Remarks

    If set to true, the file will contain pixel scale and real-world coordinate information. World files are not generated for Layout exports.

    If you export a 3D view, this parameter will be ignored regardless of the setting because world files are not applicable to 3D views.

    (The default value is false)

    Example
    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);
          }
        });
      }
    }
    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
      }
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also