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.
//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
publicclass ExportLayoutToPNGExample
{
publicstatic 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);
}
});
}
}
//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
publicclass ExportMapFrameToPNGExample
{
publicstatic 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);
}
});
}
}
//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
publicclass ExportActiveMapToPNGExample
{
publicstatic 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);
}
});
}
}