Jui-Shu Yeh
Jui-Shu Yeh

Reputation: 13

How to display one image on top of another?

I want to add a watermark on a dm3 image and be able to specify the size and position of the watermark

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

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

However, the watermark image is not shown on image in this script.

Upvotes: 1

Views: 94

Answers (1)

BmyGuest
BmyGuest

Reputation: 2949

You need to understand the concept of Components better. Both ImageDisplays and Annotations are Components. An ImageDocument is the container (to be serialized to disc) which contains one or more components, most typically an imageDisplay only. All Components can have children, so any annotation on an image really is a annotation-component child on an ImageDisplay-component. This also goes for other images displayed on an image. You want to add an ImageDisplay as child of another ImageDisplay such as:

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)

Upvotes: 0

Related Questions