APLX Help
: System Classes
: Methods
: Overlay
|
|
![]() |
The 'Overlay' method |
Argument: Nested or integer vector (see text) Valid for: Image The Overlay method allows you to overlay one image (the foreground image) on to another (the background image). If the foreground image is transparent, the background image will be partially visible through the foreground image. The background image should first be loaded into an Image object. You then copy the foreground image to a specified location on the background image. The foreground image usually comes from a file, but it can come from another Image object. To load a foreground image from file, call the Overlay method with this syntax: Image.Overlay 'file_name' Top Left <Mode> or 'ImageName' ⎕WI 'Overlay' 'file_name' Top Left <Mode> where file_name is the name of the file to load (one of the standard formats supported by ImageMagick), and Top and Left are the positions in the Image control where it should be loaded (these can be omitted, in which case 0 0 is assumed). If the file name is an empty vector, a dialog will be invoked to allow the user to select a file. The last parameter Mode is normally not needed - see below. To load a foreground image from another Image object, call the Overlay method with this syntax: Image.Overlay Handle Top Left <Mode> or 'ImageName' ⎕WI 'Overlay' Handle Top Left <Mode> where the Handle parameter is an integer representing the handle property of the source Image object. This is very useful if you want to create the foreground image dynamically, or load a non-transparent image and make it transparent (see the Setopacity method) This function loads a background image from file, and places a foreground image (also from file) over it: ∇DEMO_Overlay;Win [1] '⎕' ⎕wi 'scale' 5 [2] Win←'⎕' ⎕NEW 'form' ⋄ Win.title←'Transparency' ⋄ Win.where←1 1 420 700 [3] Win.Pic.new 'Picture' [4] Win.Pic.Img.new 'Image' ⋄ Win.Pic.Img.scale←5 ⋄ Win.Pic.align←¯1 [5] Win.Pic.Img.file←'c:\pictures\background.jpg' [6] Win.Pic.Img.Overlay 'c:\pictures\foreground.png' 200 120 [7] ⊣1 ⎕WE Win ∇ This version of the function does the same, but uses a second Image object to hold the foreground image and transform it, before copying it into the background: ∇DEMO2_Overlay;Win;Img2;handle [1] '⎕' ⎕wi 'scale' 5 [2] Win←'⎕' ⎕NEW 'form' ⋄ Win.title←'Transparency' ⋄ Win.where←1 1 420 700 [3] Win.Pic.new 'Picture' [4] Win.Pic.Img.new 'Image' ⋄ Win.Pic.Img.scale←5 ⋄ Win.Pic.align←¯1 [5] Win.Pic.Img.file←'c:\pictures\background.jpg' [6] ⍝ Create a second (invisible) image object: [7] Img2←'⎕' ⎕new 'Image' [8] Img2.file←'c:\pictures\foreground.png' [9] Img2.Transform 'Flip' [10] handle←Img2.handle [11] Win.Pic.Img.Overlay handle 200 120 [12] ⊣1 ⎕WE Win ∇ The 'mode' parameterThe underlying ImageMagick call which does the copying is MagickCompositeImage(). If you omit the final Mode parameter, this is called with the 'compose' type set to AtopCompositeOp, which means that the foreground image is placed over the background image. This is the most common requirement. However, there are other possible values which you can specify as the Mode parameter. These are defined in an 'enum' called CompositeOperator in the ImageMagick source; unfortunately, the exact values of the mode parameter may vary from one release of ImageMagick to another, so you will need to check the ImageMagick include files (composite.h) to get the numeric values for the particular version you are using - they start with UndefinedCompositeOp = 0. Useful values include: OverCompositeOp InCompositeOp OutCompositeOp AtopCompositeOp XorCompositeOp PlusCompositeOp MinusCompositeOp AddCompositeOp SubtractCompositeOp DifferenceCompositeOp MultiplyCompositeOp BumpmapCompositeOp ReplaceCompositeOp CopyCompositeOp CopyRedCompositeOp CopyGreenCompositeOp CopyBlueCompositeOp ClearCompositeOp DissolveCompositeOp DarkenCompositeOp LightenCompositeOp HueCompositeOp SaturateCompositeOp ColorizeCompositeOp LuminizeCompositeOp ScreenCompositeOp CopyCyanCompositeOp CopyMagentaCompositeOp CopyYellowCompositeOp CopyBlackCompositeOp ColorDodgeCompositeOp HardLightCompositeOp SoftLightCompositeOp |
|
APLX Help
: System Classes
: Methods
: Overlay
|
Copyright © 1996-2010 MicroAPL Ltd