Derives an alpha channel from the image on the canvas.



Canvas.Select inType, inParams


Name   Type   Description
inType String The type of selection - "all" or "none" or "color" or "notcolor".
inParams String A parameter string containing Selection parameters.



This method allows you to derive an alpha channel from the contents of an image. For example you could create an alpha channel based on all the white parts of an image. Parts of the image that are selected are visible, parts that are not selected are transparent.

You can choose from the following selection types:

  • "all" - select everything as visible
  • "none" - everything as transparent
  • "color" - parts of the image which match a particular key color, visible
  • "notcolor" - parts of the image which match a particular key color, transparent

Additionally you can use the Mode parameter to specify add and sub modes to modify existing selections. For example the following code will make all black and all white portions of an image transparent.

canv.Select "all", ""
canv.Select "color", "keycolor=0xFF,0xFF,0xFF tolerance=10.0 mode=submin"
canv.Select "color", "keycolor=0x00,0x00,0x00 tolerance=10.0 mode=submin"

The first selection makes all portions of the image 100% opaque. The second would normally make all white portions of the image 100% opaque and all others 0% opaque. However because we're using the submin mode the effect is actually to subtract 100% from the current opacity where the image is white and to subtract 0% where the image is not white. The same effect occurs in the third line and black is made transparent.

See Also

Mode parameter.



Set theObj = Server.CreateObject("ImageGlue7.Canvas")
theObj.DrawFile Server.MapPath("boat.gif"), ""
' white transparent with a little tolerance
theObj.Select "notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0"
theObj.SaveAs Server.MapPath("alphaboat.png"), "alpha=true"

The code above draws the image mypic onto a canvas. It then selects everything that is white and saves the completed image with selection-as-alpha-channel into a png. The input and output images are shown below.



Set ca1 = Server.CreateObject("ImageGlue7.Canvas")
ca1.DrawFile Server.MapPath("boat.gif"), ""
' white transparent with a little tolerance
ca1.Select "notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0"
Set ca2 = CreateObject("ImageGlue7.Canvas")
ca2.Color = "red"
ca2.Width = ca1.Width
ca2.Height = ca1.Height
ca2.DrawCanvas ca1.Image, "Mode=Transparent"
ca2.SaveAs Server.MapPath("redboat.jpg"), ""

The code above selects all the white - or nearly white - pixels in the image and replaces them with red ones before saving the final output as a JPEG. The final output is shown below.