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 :
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:
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+ "')");
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+"')");