【问题标题】:How to display one image on top of another?如何将一个图像显示在另一个图像之上?
【发布时间】:2021-07-14 02:58:43
【问题描述】:

我想在 dm3 图像上添加水印并能够指定水印的大小和位置

image front := GetFrontImage()
ImageDocument imageDoc = GetFrontImageDocument()
ImageDisplay imgDisplay = ImageGetImageDisplay(front,0)

image img2 := OpenImage("WaterMark.jpg")
imageDoc.ImageDocumentAddImage( img2 )

但是,此脚本中的图像上不显示水印图像。

【问题讨论】:

  • 欢迎来到 StackOverflow,感谢您的提问。请记住对答案进行投票并接受(勾选)您认为最能解决您的问题的答案。
  • 感谢您的回复并编辑我的问题。

标签: dm-script


【解决方案1】:

你需要更好地理解组件的概念。 ImageDisplays 和 Annotations 都是 Components。 ImageDocument 是包含一个或多个组件的容器(将被序列化到磁盘),最典型的是仅 imageDisplay。 所有组件都可以有子组件,因此图像上的任何注释实际上都是 ImageDisplay 组件上的注释组件子组件。这也适用于图像上显示的其他图像。您想添加一个 ImageDisplay 作为另一个 ImageDisplay 的子项,例如:

image img:= realImage("Test",4,500,500)
img = icol
img.ShowImage()

image icon := realImage("Icon",4,100,100)
icon = iradius

// Adding icon onto parent, it will be 0/0 aligned
imageDisplay parentDisp = img.ImageGetImageDisplay(0)
imageDisplay childDisp = icon.NewImageDisplay("best")
parentDisp.ComponentAddChildAtEnd(childDisp)

// Move icon to bottom right corner. 10% (of icon size) shifted inward
number nx = 500 // x-position at which control point of component should be placed
number ny = 500 // y-position at which control point of component should be placed
number rx = 1.1 // relative x position of control point of component within component rect. (0.0=left 1.0=right)
number ry = 1.1 // relative y position of control point of component within component rect. (0.0=top 1.0=bottom)
number doH = 1  // command will shift horizontally (true/false)
number doV = 1  // command will shift vertically (true/false)
childDisp.ComponentPositionAroundPoint(nx,ny, rx,ry, doH,doV)

OKDialog("Now show move/scaling by transformation.")
// Scale and position componets on their parents.
number offsetX = -200   // x shift of component in parent's coordinate system
number offsetY = -100   // y shift of component in parent's coordinate system
number scaleX = 0.8     // x-scale (relative) of component
number scaleY = 0.8     // y-scale (relative) of component. Note: Not all components can scale x/y indepently
childDisp.ComponentTransformCoordinates(offsetX,offsetY,scaleX,scaleY)

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 2016-04-11
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多