C# ExportFormat xWidth, yHeight dimensions from MapView.Active.Extent

766
3
08-27-2018 10:40 AM
MikeRatcliffe
Occasional Contributor

I'd like to get the pixel width and height from the MapView.Active.Extent or Camera or Geometry to feed ExportFormat's Height/Width.  I do this so the exported dimensions of the Tiff etc. match the MapView Extent as the user might expect.

Reference:  

ProSnippets Layouts · Esri/arcgis-pro-sdk Wiki · GitHub 

0 Kudos
3 Replies
MikeRatcliffe
Occasional Contributor

I can cheat to get usable (printable) results from ExportFormat with the parameter settings formula below:

(96ppi resolution, 1080p height, 1920 width)*3

Yields:

Resolution = 288,

Height = 3240,

Width = 5760,

Exporting a .tiff produces a 1MB file that does not truncate the mapview if the native resolution of your monitor is 1920x1080.

This is a cheat, not a real solution to the question above.

0 Kudos
CharlesMacleod
Esri Regular Contributor

Is this what you are looking for?

mapView.GetViewSize()

MikeRatcliffe
Occasional Contributor

Thanks, Charles.  .GetViewSize() is what I needed, but I still had to implement the 'cheat' above to get anything that resembled the actual mapview aspect ratio without truncating it.  (This interface won't let me attach images above 1920x1080.)  I believe this method would ALSO work if the user merely wanted a low-res screenshot--just delete the *3 multipliers from resolution, height, width. Here's where I ended up:

---------------------------------------------------------------------------------

private async void Xprt_mv_Click(object sender, EventArgs e)
{
await ActMap();

if (File.Exists(GVar.DL + @"temp\MapView.tiff"))
{
File.Delete(GVar.DL + @"temp\MapView.tiff");
}
if (File.Exists(GVar.DL + @"temp\MapView.tfw"))
{
File.Delete(GVar.DL + @"temp\MapView.tfw");
}

await QueuedTask.Run(() =>
{
MapView activeMapView = MapView.Active;
var mvs = activeMapView.GetViewSize(); //get active mapview size
double mvsh = (mvs.Height)*3; //set height variable *3 for printable resolution
double mvsw = (mvs.Width)*3; //set width variable *3 for printable resolution
int ResoMultiplied = 96 * 3; //native System display resolution 96ppi *3 for printable resolution

if (activeMapView != null)
{
TIFFFormat Tiff = new TIFFFormat()
{
Resolution = ResoMultiplied, //use resolution multiplied
Height = mvsh, //use height variable
Width = mvsw, //use width variable
HasWorldFile = true,
OutputFileName = GVar.DL + @"temp\MapView.tiff"
};

//Export active map view
if (Tiff.ValidateOutputFilePath())
{
activeMapView.Export(Tiff);
}
try
{
string filepath = GVar.DL + @"temp\";
Process.Start(filepath);
}
catch (Exception)
{
MessageBox.Show("Could not open the image's containing folder because it does not exist.", " Missing FilePath",
MessageBoxButtons.OK,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
return;
}
// emf, eps, gif, jpeg, pdf, png, svg, tga, tiff formats also available for export
}
});
}

0 Kudos