我正在 Enterprise Architect C# 插件中处理表单。我需要通过自动化将图像添加到图像管理器,因为通过在元素/包注释中设置指向它们的超链接,我可以使用 EA API Repository.ExtractImagesFromNote () 将图像导出到外部路径。
在常用的工具箱中,有一个图像元素。在拖放时,它会自动打开图像管理器以为其设置备用图像。我还注意到这个图像没有显示在项目浏览器中(是因为它是一个非 UML 元素吗?)。
我尝试通过自动化添加此图像元素,如下所示:
EA.Element testImg = viewPkg.Elements.AddNew(imagePath, "Image")
元素的创建如下所示:
它创建了一个图像 Assets (来自工件工具箱)而不是图像元素(来自通用工具箱)。
我需要将图像添加到图像管理器。我请求帮助从通用工具箱创建图像元素并通过代码而不是图像 Assets 为其设置图像。
我还注意到图像管理器中的这个选项:
更新 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+ "')");
我更新了下面的代码,用于将 .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/