Inserts one canvas into a color or alpha channel on another.

 

   
Syntax
 
     

[Visual Basic]
Sub SetChannel(inChannel As String, inImage As IntPtr)

[C#]
void SetChannel(string inChannel, IntPtr inImage);

 

   
Params
 
     
Name   Description
inChannel The name of the channel.
inImage The Image from the Canvas to use as an intensity map.

 

   
Notes
 
     

This allows you to insert a color channel using another Canvas as an intensity map. Most commonly you will want to use this method to insert an alpha channel using another Canvas as a matte. You can use then use blends and transparencies (both are specified using alpha channels).

The depth of the Canvas will be set to 'millions' as soon as you insert a channel. If the sizes of the two Canvases do not match the intensity map Canvas will be stretched to the correct size.

The channel names you can use are:

  • "red"
  • "green"
  • "blue"
  • "alpha"

 

   
See Also
 
     

Canvas Image property.
Canvas DrawCanvas function.
Mode
parameter.
Alpha Channels
.

 

   
Example
 
     

[Visual Basic]
Dim bg As New Canvas
Dim stamp As New Canvas
Dim mask As New Canvas
' create canvas
bg.Color = System.Drawing.Color.Blue
bg.Width = 100
bg.Height = 90
mask.DrawFile(Server.MapPath("rez/cloud.gif"), "")
stamp.Width = mask.Width
stamp.Height = mask.Height
' first draw white cloud
stamp.Color = System.Drawing.Color.White
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=10,10 Mode=Transparent")
' ... then light gray cloud
stamp.Color = System.Drawing.Color.LightGray
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=60,10 Mode=Transparent")
' ... then dark gray cloud
stamp.Color = System.Drawing.Color.Gray
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=10,60 Mode=Transparent")
' ... then black cloud
stamp.Color = System.Drawing.Color.Black
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=60,60 Mode=Transparent")
' finally save image
bg.SaveAs(Server.MapPath("setchannel.jpg"), "Quality=high")

[C#]
Canvas bg = new Canvas();
Canvas stamp = new Canvas();
Canvas mask = new Canvas();
// create canvas;
bg.Color = System.Drawing.Color.Blue;
bg.Width = 100;
bg.Height = 90;
mask.DrawFile(Server.MapPath("rez/cloud.gif"), "");
stamp.Width = mask.Width;
stamp.Height = mask.Height;
// first draw white cloud;
stamp.Color = System.Drawing.Color.White;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=10,10 Mode=Transparent");
// ... then light gray cloud;
stamp.Color = System.Drawing.Color.LightGray;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=60,10 Mode=Transparent");
// ... then dark gray cloud;
stamp.Color = System.Drawing.Color.Gray;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=10,60 Mode=Transparent");
// ... then black cloud;
stamp.Color = System.Drawing.Color.Black;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=60,60 Mode=Transparent");
// finally save image;
bg.SaveAs(Server.MapPath("setchannel.jpg"), "Quality=high");

The above draws four solid blocks of color using an alpha channel as a matte. The input and output files are shown below.

cloud.gif

setchannel.jpg