c# - 用于将图像添加到图像管理器的 Enterprise Architect API

标签 c# image element enterprise-architect

我正在 Enterprise Architect C# 插件中处理表单。我需要通过自动化将图像添加到图像管理器,因为通过在元素/包注释中设置指向它们的超链接,我可以使用 EA API Repository.ExtractImagesFromNote () 将图像导出到外部路径。

在常用的工具箱中,有一个图像元素。在拖放时,它会自动打开图像管理器以为其设置备用图像。我还注意到这个图像没有显示在项目浏览器中(是因为它是一个非 UML 元素吗?)。

我尝试通过自动化添加此图像元素,如下所示:

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

元素的创建如下所示:

enter image description here

它创建了一个图像 Assets (来自工件工具箱)而不是图像元素(来自通用工具箱)。

我需要将图像添加到图像管理器。我请求帮助从通用工具箱创建图像元素并通过代码而不是图像 Assets 为其设置图像。

我还注意到图像管理器中的这个选项:

enter image description here

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

enter image description here enter image description here

我更新了下面的代码,用于将 .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);

我正在使用 repository.execute 命令将这个值插入到 t_image 表中:

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

最佳答案

实际上是创建一个 <<image>> Artifact (或者您可以使用 Boundary )并为其分配备用图像。图片需要放在EA的图片库中。您可以阅读 this SO answer如何实现。

关于c# - 用于将图像添加到图像管理器的 Enterprise Architect API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50904445/

相关文章:

image - 提供即时调整大小的图像

java - 最有效的图像显示方式

c# - C# 中事件和更改标记之间的区别

c# - 窗口 SizeToContent 和 ListBox 大小调整

c# - 关于so​​ckets的listening和backlog的问题

c# - 多个 group by 和 Sum LINQ

java - 如何将 ImageIcon 设置为 JButton 并根据按钮的大小调整图片大小?

xml - 在 scala 中将 XML 元素解析为 Dataframe

css - 网页浏览器页面缩小时元素不 float (Ctrl -)

python - 使用 Selenium 选择具有更改值的单选按钮