1
votes

I am working on forms in Enterprise Architect C# add-ins. I need to add images to the image manager through automation because by setting hyperlink to them in element/package notes, I am able export the images to external path using the EA API Repository.ExtractImagesFromNote ().

In common toolbox, there is an image element. On dragging and dropping it automatically opens the image manager to set an alternate image to it. I also noticed that this image was not displayed in the project browser (is it because it is a non-UML element?).

I tried adding this image element through automation as shown below:

EA.Element testImg = viewPkg.Elements.AddNew(imagePath, "Image")

The elements gets created as shown :

enter image description here

It had created an image asset ( from the artifacts toolbox) and not the image element (from the common toolbox).

I need the image to be added to image manager. I request help for creating image element from common toolbox and setting an image to it through code instead of the image asset.

I also noticed this option in Image Manager:

enter image description here

Current Code for updating t_image table:

string base64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(@"C:\\Users\\Desktop\\Figure 1.1.bmp"));
Session.Repository.Execute("INSERT INTO t_image VALUES('0000000002','test200','Bitmap','"+base64+ "')");

enter image description here enter image description here

I have updated the code as below for converting image in .png to base64 encoded string

var imageStream = new MemoryStream();
Bitmap resized = new Bitmap(img, new Size(img.Width / 5,  img.Height / 5));
resized.Save(imageStream, ImageFormat.Png);
imageStream.Position = 0;
var imageBytes = imageStream.ToArray();
ImageBase64 = Convert.ToBase64String(imageBytes, 0, imageBytes.Length);

I am inserting this value to the t_image table using the repository.execute command:

 Session.Repository.Execute("INSERT INTO t_image VALUES(" + imgCount + ",'" + imgPath+".bmp" + "','Bitmap','"+ImageBase64+"')");
1
You want to programatically add image to image manager in EA ?Dah Sra
@Arshad thank you..I referred it previously. I want to use the image element from common toolbox. Is it possible?rashmi

1 Answers

3
votes

What that does is actually creating an <<image>> Artifact (or you can use a Boundary) and assigning an alternate image to it. The image needs to be placed in EA's image library. You can read in this SO answer how to achieve that.