I am a beginner of Maps SDK for .NET and try to understand "Capture a map/layout to the clipboard" function.
ArcGIS Pro GUI
Share tab > in the Output group, 'Capture To Clipboard'
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/capture-a-map-or-layout-to-the-clipbo...
I understood GetPlugInWrapper ia able to call DAML ID:"esri_sharing_CaptureMapToClipboard".
https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic10151.html
However, my end user hope to use 'Capture To Clipboard' in an active map without right upper nortification "Capture Map to Clipboard. The Iimage was captured and copied to the clipboard.
After clcik 'Capture To Clipboard', the right upper nortification always displayed, so GetPlugInWrapper is unusable for my end user request.
Does anyone has other implementation ideas?
If there is no way to complete processes by only using Pro SDK, I think that Pro SDK only run export images and .NET run subsequent processing.
You can use the CaptureThumnail method on the map view and get a BitmapSource. This can be passed to the System clipboard.
Here is a small snippet.
protected override async void OnClick()
{
var mapView = MapView.Active;
if (mapView == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No active map view");
return;
}
await QueuedTask.Run(() =>
{
//width of the mapview extent
MapPoint ptXMaxYMin = MapPointBuilderEx.CreateMapPoint(mapView.Extent.XMax, mapView.Extent.YMin, mapView.Map.SpatialReference);
MapPoint ptXMinYMin = MapPointBuilderEx.CreateMapPoint(mapView.Extent.XMin, mapView.Extent.YMin, mapView.Map.SpatialReference);
var screenPtXMaxYMin = mapView.MapToScreen(ptXMaxYMin);
var screenPtXMinYMin = mapView.MapToScreen(ptXMinYMin);
var width = screenPtXMaxYMin.X - screenPtXMinYMin.X;
//Height of the mapview extent
MapPoint ptXMinYMax = MapPointBuilderEx.CreateMapPoint(mapView.Extent.XMin, mapView.Extent.YMax, mapView.Map.SpatialReference);
var screenPtXMinYMax = mapView.MapToScreen(ptXMinYMax);
var height = screenPtXMinYMin.Y - screenPtXMinYMax.Y;
var thumbnail = mapView.CaptureThumbnail((int)width, (int)height);
CopyBitmapSourceToClipboard(thumbnail);
});
}
public static void CopyBitmapSourceToClipboard(BitmapSource image)
{
if (image == null)
{
throw new ArgumentNullException(nameof(image), "BitmapSource cannot be null.");
}
try
{
Clipboard.SetImage(image);
}
catch (Exception ex)
{
// Handle potential exceptions, such as COMException if clipboard is in use
Console.WriteLine($"Error copying image to clipboard: {ex.Message}");
}
}