GIF files are a legacy raster format for use on the web. GIFs cannot contain more than 256 colors (8-bits per pixel),
which along with optional lossless compression, makes them smaller than other file formats.
//This example demonstrates how to export a layout to GIF.
//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 ExportLayoutToGIFExample
{
publicstatic Task ExportLayoutToGIFAsync(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 GIF format with appropriate settings
GIFFormat GIF = new GIFFormat();
GIF.Resolution = 300;
GIF.OutputFileName = Path;
return QueuedTask.Run(() =>
{
//Export Layout
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
if (GIF.ValidateOutputFilePath())
{
lyt.Export(GIF);
}
});
}
}
//This example demonstrates how to export an individual map frame on a layout to GIF.
//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 ExportMapFrameToGIFExample
{
publicstatic Task ExportMapFrameToGIFAsync(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 GIF format with appropriate settings
GIFFormat GIF = new GIFFormat();
GIF.HasWorldFile = true;
GIF.Resolution = 300;
GIF.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;
GIF.OutputFileName = Path;
if (GIF.ValidateOutputFilePath())
{
mf.Export(GIF);
}
});
}
}