Select to view content in your preferred language

Any way to add graphic image from memory to map or layout

777
2
06-23-2020 11:53 PM
by Anonymous User
Not applicable

Hi Guys,

I am currently developing an addin which will generate the image from memory dynamically (using system.Drawing c#)

And would like to check is there anyway to load the image into map or layout.

Those images shall represent soil sample information from particular point feature.

I found this method LayoutElementFactory.Instance.CreatePictureGraphicElement , but it can only be usable with file path.

So I have to save memory stream into file temporarily and load as element and delete the file.

Is there any way to load dynamically? Uma Harano

0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

Hi

Here is a code snippet that worked for me -

      await QueuedTask.Run(() =>
      {
        LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault();
        var layout = layoutItem.GetLayout();
        //Build 2D point geometry  
        Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);

        Image newImage = Image.FromFile(@"C:\Users\...\Image.png");
        var stream = new System.IO.MemoryStream();
        newImage.Save(stream, ImageFormat.Png);
        stream.Position = 0;
        CIMMarker markerFromStream = SymbolFactory.Instance.ConstructMarkerFromStream(stream);

        CIMPointSymbol pointSymbolFromStream = SymbolFactory.Instance.ConstructPointSymbol(markerFromStream);
        //pointSymbolFromStream.SetSize(50);

        //create a CIMGraphic 
        var graphic = new CIMPointGraphic()
        {
          Symbol = pointSymbolFromStream.MakeSymbolReference(),
          Location = MapPointBuilder.CreateMapPoint(coord2D)
        };

        GraphicElement ptElm = LayoutElementFactory.Instance.CreateGraphicElement(layout, graphic);
        ptElm.SetName("New Point");
      });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
by Anonymous User
Not applicable

Hi Uma Harano‌,

CreateGraphicElement method cannot be found in the 2.5 sdk, but I can use CreatePointGraphicElement and solve it.

LayoutElementFactory.Instance.CreateGraphicElement

Can I get advice on how to get the Coordinate2D of mapPoint in layout view.

Normally It is MapPoint geometry for a point feature in mapview /map, but how to locate it in Layout view -> map frame -> map view.

0 Kudos