Derives an alpha channel from the image on the canvas.

 

   
Syntax
 
     

[Visual Basic]
Sub Select(inType As String, inParams As String)

[C#]
void Select(string inType, string inParams);

 

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

 

   
Notes
 
     

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.

[Visual Basic]
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")

[C#]
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.

 

   
Example
 
     

[Visual Basic]
Dim theObj As New Canvas
theObj.DrawFile(Server.MapPath("rez/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")

[C#]
Canvas theObj = new Canvas();
theObj.DrawFile(Server.MapPath("rez/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.

boat.gif

alphaboat.png

[Visual Basic]
Dim ca1 As New Canvas
ca1.DrawFile(Server.MapPath("rez/boat.gif"), "")
' white transparent with a little tolerance
ca1.Select("notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0")
Dim ca2 As New Canvas
ca2.Color = System.Drawing.Color.Red
ca2.Width = ca1.Width
ca2.Height = ca1.Height
ca2.DrawCanvas(ca1.Image, "Mode=Transparent")
ca2.SaveAs(Server.MapPath("redboat.jpg"), "")

[C#]
Canvas ca1 = new Canvas();
ca1.DrawFile(Server.MapPath("rez/boat.gif"), "");
// white transparent with a little tolerance;
ca1.Select("notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0");
Canvas ca2 = new Canvas();
ca2.Color = System.Drawing.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.

redboat.jpg