Book a Demo

Author Topic: Export diagram to image  (Read 10982 times)

Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Export diagram to image
« on: February 06, 2012, 03:45:55 pm »
Hi, is there a way via the automation interface to export a diagram to a image.  Basically we are developing an addin to report of our EA database.  In the report we would like to have screen shots of the diagrams.

Thanks :)

Shaggy Man

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Export diagram to image
« Reply #1 on: February 06, 2012, 05:54:13 pm »
Get Project interface(using Repository.GetProjectInterface()) and
use Project.PutDiagramImageToFile().

see www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.htm


Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Export diagram to image
« Reply #2 on: February 06, 2012, 05:58:05 pm »
Thanks for your help

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Export diagram to image
« Reply #3 on: February 06, 2012, 06:13:51 pm »
This is how I use it to get an Image property from my Diagram wrapper class:
Code: [Select]
public Image image
{
      get
      {
            EA.Project projectInterface = this.model.getWrappedModel().GetProjectInterface();
            string diagramGUID = projectInterface.GUIDtoXML(this.wrappedDiagram.DiagramGUID);
            string filename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
            //save diagram image to file (format ".png")
            projectInterface.PutDiagramImageToFile(diagramGUID, filename, 1);
            //load the contents of the file into a memorystream
            MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(filename));
            //then create the image from the memorystream.
            //this allows us to delete the temporary file right after loading it.
            //When using Image.FromFile the file would have been locked for the lifetime of the Image
            Image diagramImage = Image.FromStream(imageStream);
            //delete the temorary file
            System.IO.File.Delete(filename);

            return diagramImage;
      }
}

Geert
« Last Edit: February 06, 2012, 06:14:32 pm by Geert.Bellekens »