如何在另一张图片上显示一张图片?

问题描述

我想在dm3图片上加水印,并且可以指定水印的大小和位置

image front := GetFrontimage()
ImageDocument imageDoc = GetFrontimageDocument()
Imagedisplay imgdisplay = ImageGetimagedisplay(front,0)

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

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

解决方法

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

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

image icon := realImage("Icon",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)