简体   繁体   English

用于将图像添加到Image Manager的Enterprise Architect API

[英]Enterprise Architect API for Adding Image to Image Manager

I am working on forms in Enterprise Architect C# add-ins. 我正在使用Enterprise Architect C#加载项中的表单。 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 (). 我需要通过自动化将图像添加到图像管理器,因为通过在元素/包注释中设置超链接,我可以使用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?). 我还注意到这个图像没有显示在项目浏览器中(是因为它是非UML元素吗?)。

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: 我还在Image Manager中注意到了这个选项:

在此输入图像描述

Current Code for updating t_image table: 更新t_image表的当前代码:

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 我更新了如下代码,用于将.png中的图像转换为base64编码的字符串

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: 我使用repository.execute命令将此值插入t_image表:

 Session.Repository.Execute("INSERT INTO t_image VALUES(" + imgCount + ",'" + imgPath+".bmp" + "','Bitmap','"+ImageBase64+"')");

What that does is actually creating an <<image>> Artifact (or you can use a Boundary ) and assigning an alternate image to it. 这样做实际上是创建一个<<image>> Artifact (或者你可以使用Boundary )并为其指定一个替代图像。 The image needs to be placed in EA's image library. 图像需要放在EA的图像库中。 You can read in this SO answer how to achieve that. 你可以阅读这个SO答案如何实现这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM