|
|
|
|
|
|
|
This example shows how to matte one image onto another using an
alpha channel. It also demonstrates a number of other useful
techniques.
|
|
|
|
|
|
|
|
|
|
We start by setting up variables pointing to the files we are
going to use.
[VBScript]
imagefile = Server.MapPath("suncolor.gif")
maskfile = Server.MapPath("sunmask.gif")
backgroundfile = Server.MapPath("mapusa.jpg")
dstfile = Server.MapPath("mapusasun.jpg")
|
|
|
|
|
|
|
|
|
|
We create a Canvas object and draw our background onto it.
Because neither the height nor width of the Canvas was defined the
Canvas is resized to the natural size of the image.
[VBScript]
Set canvas = Server.CreateObject("ImageGlue7.Canvas")
canvas.DrawFile backgroundfile, ""
|
|
|
|
|
|
|
|
|
|
Next we create a Canvas for the image we are going to draw onto
our background. There are two parts for this image - the visible
part and the alpha channel which defines a mask for the image. We
draw each of these pictures onto a Canvas and then insert the alpha
channel into our visible image. Finally we Clear the mask seeing as
we are not going to be using it again and it is occupying memory
which could be more valuably utilized.
[VBScript]
Set src = Server.CreateObject("ImageGlue7.Canvas")
Set mask = Server.CreateObject("ImageGlue7.Canvas")
src.DrawFile imagefile, ""
mask.DrawFile maskfile, ""
src.SetChannel "alpha", mask.Image
mask.Clear
|
|
|
|
|
|
|
|
|
|
We are going to draw five images matted into the background. To
do this we have to draw using transparent mode. The first image is
offset 30 pixels down and 30 to the right from the top left.
Because DrawCanvas returns the rectangle used for drawing each
image will be drawn offset from the last one. We end up with a
diagonal line of images stretching down from the top left of the
Canvas.
[VBScript]
params = "Mode=transparent Move=30,30 Rect="
rect = "0,0," & src.Width & "," & src.Height
For i = 1 To 5
rect = canvas.DrawCanvas(src.Image, params &
rect)
Next
|
|
|
|
|
|
|
|
|
|
Finally we save the Canvas out as a file.
[VBScript]
canvas.SaveAs dstfile, ""
|
|
|
|
|
|
|