如何通过脚本打开带有注释的图像
How to open an image with annotations by script
如何在 dm-script 的脚本中打开带有注释的 (dm4) 图像?
当 dm4 图像有注释(例如比例尺或一些文本)时,当我通过菜单 (Ctrl + O) 打开图像时会显示。但是当我通过 openImage()
在脚本中打开同一个文件时,它们不会如下所示显示。
左边是通过菜单打开的图片,右边是openImage()
打开的图片。它缺少注释。
下面的例子说明了同样的事情。该代码将文本添加到图像,保存并再次打开。打开的图片没有像上图那样显示标注:
String path = GetApplicationDirectory("current", 0);
path = PathConcatenate(path, "temp.dm4");
// get the current image
image img;
img.getFrontImage();
ImageDisplay display = img.ImageGetImageDisplay(0);
// add some test annotations
number height = img.ImageGetDimensionSize(1);
number padding = height / 100;
number font_size = height/10;
for(number y = padding; y + font_size + padding < height; y += font_size + padding){
Component annotation = NewTextAnnotation(padding, y, "Test", font_size);
annotation.componentSetForegroundColor(255, 255, 255);
display.ComponentAddChildAtEnd(annotation);
}
// save the current image
img.saveImage(path);
// show the saved image
image img2 = openImage(path);
img2.showImage();
倒数第二行有误。
通过使用 =
而不是 :=
,您将(仅值)从打开的图像复制到新图像中。你想做
image img2 := openImage(path)
这是一个相当典型的脚本新手犯的错误,因为这是一种 "specialty" 在其他语言中找不到的脚本语言。它的出现是因为脚本旨在启用非常简单的脚本,例如 Z = log(A)
,其中通过处理现有图像(此处为 A)即时创建新图像(此处为 Z)。
所以当一个人想要分配一个图像给一个变量时,需要一个different运算符。
有关详细信息,请参阅此处的 F1 帮助文档:
相同的逻辑/错误来源涉及在 "finding" 图像、"creating new images" 和克隆图像(带有元数据)时使用 :=
而不是 =
。
尝试两者时请注意差异:
image a := RealImage("Test",4,100,100)
ShowImage(a)
image b = RealImage("Test",4,100,100)
ShowImage(b)
和
image a := GetFrontImage()
a = 0
image b = GetFrontImage()
b = 0
和
image src := GetFrontImage()
image a := ImageClone( src )
showImage(a)
image b := ImageClone( src )
showImage(b)
如何在 dm-script 的脚本中打开带有注释的 (dm4) 图像?
当 dm4 图像有注释(例如比例尺或一些文本)时,当我通过菜单 (Ctrl + O) 打开图像时会显示。但是当我通过 openImage()
在脚本中打开同一个文件时,它们不会如下所示显示。
左边是通过菜单打开的图片,右边是openImage()
打开的图片。它缺少注释。
下面的例子说明了同样的事情。该代码将文本添加到图像,保存并再次打开。打开的图片没有像上图那样显示标注:
String path = GetApplicationDirectory("current", 0);
path = PathConcatenate(path, "temp.dm4");
// get the current image
image img;
img.getFrontImage();
ImageDisplay display = img.ImageGetImageDisplay(0);
// add some test annotations
number height = img.ImageGetDimensionSize(1);
number padding = height / 100;
number font_size = height/10;
for(number y = padding; y + font_size + padding < height; y += font_size + padding){
Component annotation = NewTextAnnotation(padding, y, "Test", font_size);
annotation.componentSetForegroundColor(255, 255, 255);
display.ComponentAddChildAtEnd(annotation);
}
// save the current image
img.saveImage(path);
// show the saved image
image img2 = openImage(path);
img2.showImage();
倒数第二行有误。
通过使用 =
而不是 :=
,您将(仅值)从打开的图像复制到新图像中。你想做
image img2 := openImage(path)
这是一个相当典型的脚本新手犯的错误,因为这是一种 "specialty" 在其他语言中找不到的脚本语言。它的出现是因为脚本旨在启用非常简单的脚本,例如 Z = log(A)
,其中通过处理现有图像(此处为 A)即时创建新图像(此处为 Z)。
所以当一个人想要分配一个图像给一个变量时,需要一个different运算符。
有关详细信息,请参阅此处的 F1 帮助文档:
相同的逻辑/错误来源涉及在 "finding" 图像、"creating new images" 和克隆图像(带有元数据)时使用 :=
而不是 =
。
尝试两者时请注意差异:
image a := RealImage("Test",4,100,100)
ShowImage(a)
image b = RealImage("Test",4,100,100)
ShowImage(b)
和
image a := GetFrontImage()
a = 0
image b = GetFrontImage()
b = 0
和
image src := GetFrontImage()
image a := ImageClone( src )
showImage(a)
image b := ImageClone( src )
showImage(b)