【问题标题】:how to let long text change to multiple lines when adding annotation to images向图像添加注释时如何让长文本变为多行
【发布时间】:2019-08-25 23:59:49
【问题描述】:

给图片添加注释时如何让长文本变为多行 并使每条线的长度相等,比如矩形?

image temp:=getfrontimage()

temp.ShowImage()
imageDisplay disp = front.ImageGetImageDisplay(0)
getsize(temp,x,y)
le=x*2/3  
to1=y*80/100
component text1 = NewTextAnnotation(le,to1,string1+","+string2+","+string3,100)

我尝试在图像中添加 3 个字符串,每个字符串有超过 15 个字母/字符,总共超过 50 个字母。

如果我将所有 3 个字符串放在一个文本注释中在线,它太长了。

如果我把它们作为 3 个文本注释,因为每一行没有完全相同数量的字母,它显示得很丑。

有没有可以让文本为多行,并且每行文本的背景长度相同?

或者3个文本注释的长度相同,我的意思是文本的背景长度相同,当每个文本注释中的字母不相同时,例如第一个文本注释为16个字母,第二个文本注释为20 个字母,第 3 个文本注释有 14 个字母,但它们的文本背景长度相同。

谢谢,

【问题讨论】:

    标签: annotations dm-script


    【解决方案1】:

    您可以像添加所有字符串一样添加换行符,只需添加换行符转义字符串\n

    示例脚本:

    number sx = 512
    number sy = 512
    image img := RealImage("test",4,sx,sy)
    img = icol
    img.ShowImage()
    
    imageDisplay disp = img.ImageGetImageDisplay(0)
    number l = sx * 2/3  
    number t = sy * 80/100
    String mLstr = "Some text line\nSome more text lines\nShort text"
    number fontSize = 12
    
    Component Line = disp.NewTextAnnotation(l,t,mLstr,fontSize)
    Line.TextAnnotationSetAlignment(1)      // 1=Left, 2=Center, 3=Right
    Line.ComponentSetDrawingMode(1)         // 1=with background, 2=without background
    Line.ComponentSetBackgroundColor(0.5,0.0,0)
    Line.ComponentSetForegroundColor(0,1,0)
    disp.ComponentAddChildAtEnd(line)
    

    注意:创建新组件时,NewTextAnnotation 命令有两种不同的变体:

    Component NewTextAnnotation( Component ref_par_comp, Number left, Number top, String text, Number size )
    Component NewTextAnnotation( Number left, Number top, String text, Number size )
    

    第一个采用附加的“父”组件。如果你使用那个,那么字体大小将与屏幕上父组件的默认显示大小一起缩放,即对于不同大小的图像不会有所不同。

    测试:只需使用 sxsy 值尝试上述脚本。然后在行注释创建行中不使用disp. 执行相同操作。

    【讨论】:

    • 谢谢,在使用 Component NewTextAnnotation( Component ref_par_comp, Number left, Number top, String text, Number size ) 时我应该为“Component ref_par_comp”添加什么?例如,Component NewTextAnnotation( Component ref_par_comp, 3 , 3, "你好", 12 ) 或 ?
    • @together 参见上面的示例。父组件,即将保存注释的组件。在大多数情况下 - 例如上面 - imageDisplay(也是一个组件)
    猜你喜欢
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 2017-10-30
    • 2021-10-28
    • 2020-08-26
    相关资源
    最近更新 更多